package org.wddsicmd.app;
 
import org.wddsicmd.app.ButtonTabComponent;
/* <-- wangmingdong -9-4-2014 0:36:11 */
import org.wddsicmd.util.ResourceBundleUtil;
/* --> wangmingdong  */

import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.Insets;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.Image;
import javax.swing.*;
import java.awt.*;
import java.io.*;
import javax.swing.text.*;
import javax.swing.event.*;
import javax.swing.Timer;

import java.awt.event.*;
import javax.swing.JTable;
import java.awt.Color;
import javax.swing.table.*;
import java.lang.Object;
import java.awt.Rectangle;
/* -2014-11-10 15:33:41 */
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
/* -2014-11-10 15:33:41 */

/* <-- wangmingdong -11-11-2014 0:15:31 */
import java.awt.Container;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.Icon;
import javax.swing.JTree;
import javax.swing.UIManager;
import javax.swing.event.TreeModelListener;
import javax.swing.filechooser.FileSystemView;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
import javax.swing.tree.DefaultTreeModel;
import java.util.*;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.Properties;
import javax.swing.border.EmptyBorder;
import javax.swing.text.Document;
/* --> wangmingdong  */
import java.util.Vector;

public class Main extends JFrame implements ActionListener {

    private final static int TAB_SINGLE_WRITE = 0;
    private final static int TAB_PUSH_IMAGE = 1;
    private final static int TAB_REMOTE_CONTROL = 2;
	
    private final static int TAB_MULTI_WRITE = 3;
    private final static int TAB_SINGLE_READ = 4;
    private final static int TAB_MULTI_READ = 5;

    private JFrame mJFrame;
    private int width, height;

/* <-- wangmingdong -9-4-2014 0:36:05 */
    protected ResourceBundleUtil labels;
/* --> wangmingdong  */
	 
    private JTabbedPane pane = new JTabbedPane();
    private JMenuItem tabItemBatchProcessing ;
    private JMenuItem menuItemIOFormatDCS ;
    private JMenuItem menuItemBitClickChange;
    private JMenuItem menuItemShiftSwitch;
    private JMenuItem scrollTabItem ;
    private JMenuItem componentTabItem;
    private final int numTab = 3;
      
    public Main(String title) {

       super(title);
System.out.println("Main 1");
	mJFrame = this;
/* <-- wangmingdong -9-4-2014 0:36:25 */
        initLabels();	
/* --> wangmingdong  */
		Image frame_icon=Toolkit.getDefaultToolkit().createImage(getClass().getResource("/org/wddsicmd/draw/images/wdtool.png"));
		setIconImage(frame_icon);

       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

System.out.println("Main 2");
       initMenu();

System.out.println("Main 3");
       add(pane);

System.out.println("Main 4");
/* doom */
        this.addComponentListener(new ComponentAdapter() {
            @Override
            public void componentResized(ComponentEvent e) {
			//System.out.println("main jframe componentResized");	
			int jframewidth = mJFrame.getWidth();
			int jframeheight = mJFrame.getHeight();
			//System.out.println("mJFrame jframewidth:"+jframewidth+" jframeheight:"+jframeheight);
			int swpanewidth = swPane.getWidth();
			int swpaneheight = swPane.getHeight();
			//System.out.println("swPane swpanewidth:"+swpanewidth+" swpaneheight:"+swpaneheight);
			layoutswPaneChilds(swpanewidth, swpaneheight);

/* -2014-11-10 15:36:35 */
			int plpanelwidth = plPanel.getWidth();
			int plpanelheight = plPanel.getHeight();
			//System.out.println("plPanel plpanelwidth:"+plpanelwidth+" plpanelheight:"+plpanelheight);
			layoutPushImageChilds(plpanelwidth, plpanelheight);
/* -2014-11-10 15:36:35 */

/* -2014-12-3 11:23:13 */
			int rcPanelwidth = rcPanel.getWidth();
			int rcPanelheight = rcPanel.getHeight();
			//System.out.println("plPanel plpanelwidth:"+plpanelwidth+" plpanelheight:"+plpanelheight);
			layoutRCChilds(rcPanelwidth, rcPanelheight);
/* -2014-12-3 11:23:13 */

            }
        });	
/* doom */
	  
    }

/* <-- wangmingdong -9-4-2014 0:36:16 */
    protected void initLabels() {
        labels = ResourceBundleUtil.getLAFBundle("org.wddsicmd.draw.Labels");
    }	
/* --> wangmingdong  */
   

    public  void runTest() {

       componentTabItem.setSelected(true);
      

System.out.println("runTest 1");
       for(int i = 0 ; i < numTab ; i++)
       {


System.out.println("runTest 2 i:"+i);
           String name = "tab "+i;
/* <-- wangmingdong -9-4-2014 0:37:34 */
           name = getTabName(i);
/* --> wangmingdong  */

System.out.println("runTest 3 i:"+i);
           pane.add(name,createContent(i));

System.out.println("runTest 4 i:"+i);
           initTabComponent(i);
System.out.println("runTest 5 i:"+i);
       }
            

       width = 1000;
	height = 600;
       setSize(new Dimension(width,height));

       setLocationRelativeTo(null);

       setVisible(true);
System.out.println("runTest 6");
      
    }

   

    private Component createContent(int index) {

	JPanel panel = null;
	switch(index){
		case TAB_SINGLE_WRITE:
			panel = createTabContentSingleWrite();
			break;
		case TAB_SINGLE_READ:
			panel = createTabContentSingleRead();
			break;
		case TAB_MULTI_WRITE:
			panel = createTabContentMultiWrite();
			break;
		case TAB_MULTI_READ:
			panel = createTabContentMultiRead();
			break;
		case TAB_PUSH_IMAGE:
			panel = createTabContentPushImage();
			break;
		case TAB_REMOTE_CONTROL:
			panel = createTabContentRC();
			break;
	}	
	return panel;	
	

    }
 

    private void initTabComponent(int i) {

       pane.setTabComponentAt(i, null);

       }
   
	public static String readValue(String filePath,String key) {
	 Properties props = new Properties();
		   try {
			InputStream in = new BufferedInputStream (new FileInputStream(filePath));
			props.load(in);
			String value = props.getProperty (key);
			   //System.out.println(key+value);
			   return value;
		   } catch (Exception e) {
			e.printStackTrace();
			return null;
		   }
	}
	
	   public static void readProperties(String filePath) {
		Properties props = new Properties();
		   try {
			InputStream in = new BufferedInputStream (new FileInputStream(filePath));
			props.load(in);
			   Enumeration en = props.propertyNames();
				while (en.hasMoreElements()) {
				 String key = (String) en.nextElement();
					   String Property = props.getProperty (key);
					   //System.out.println(key+Property);
				   }
		   } catch (Exception e) {
			e.printStackTrace();
		   }
	   }
	
	   public static void writeProperties(String filePath,String parameterName,String parameterValue) {
		Properties prop = new Properties();
		try {
		 InputStream fis = new FileInputStream(filePath);
			   prop.load(fis);
			   OutputStream fos = new FileOutputStream(filePath);
			   prop.setProperty(parameterName, parameterValue);
			   prop.store(fos, "Update '" + parameterName + "' value");
		   } catch (IOException e) {
			System.err.println("Visit "+filePath+" for updating "+parameterName+" value error");
		   }
	   }

       private String getConfigPropertiesFile(){
		String osStr = System.getProperties().getProperty("os.name");
		if(osStr != null && "Linux".equals(osStr)){
			return "/tmp/cfgProperties.xml";
		}else{
			return "C:\\adb\\cfgProperties.xml";
		}
       }

	private boolean ioFormatDCSSelected(){
		String ioFormat = readValue(getConfigPropertiesFile(), "ioformat");
		if(ioFormat != null && ioFormat.equals("DCS")){
			return true;
		}else{
			return false;
		}
	}
	private boolean bitClickChangedSelected(){
		String bitclick = readValue(getConfigPropertiesFile(), "bitclick");
		if(bitclick != null && bitclick.equals("true")){
			return true;
		}else{
			return false;
		}
	}
	private boolean isShiftClosed(){
		String shiftclose = readValue(getConfigPropertiesFile(), "shiftclose");
		if(shiftclose != null && shiftclose.equals("true")){
			return true;
		}else{
			return false;
		}
	}

    private void initMenu() {

       JMenuBar mb = new JMenuBar();

/* doom 
       tabItemBatchProcessing = new JCheckBoxMenuItem(getLablesString("tab_multi_write"));
        tabItemBatchProcessing.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B,InputEvent.CTRL_MASK));
       tabItemBatchProcessing.addActionListener(new ActionListener() {          
           @Override
           public void actionPerformed(ActionEvent arg0) {
		if(mBatch){
			mBatch = false;
			batchSwtich(mBatch);
			swPane.repaint();
		}else{
			mBatch = true;
			batchSwtich(mBatch);
			swPane.repaint();
		}
           }
       });
 doom */
        menuItemIOFormatDCS = new JCheckBoxMenuItem("DCS\u683c\u5f0f");
        menuItemIOFormatDCS.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E,InputEvent.CTRL_MASK));
       menuItemIOFormatDCS.addActionListener(new ActionListener() {          
           @Override
           public void actionPerformed(ActionEvent arg0) {
				boolean state = ((JCheckBoxMenuItem)menuItemIOFormatDCS).getState();
				//System.out.println("ioformat actionPerformed state:"+state);
				if(state){
					writeProperties(getConfigPropertiesFile(), "ioformat", "DCS");
				}else{
					writeProperties(getConfigPropertiesFile(), "ioformat", "generic");
				}
				//String ioFormat = readValue(getConfigPropertiesFile(), "ioformat");
				//if(ioFormat != null)
					//System.out.println("ioformat actionPerformed ioFormat:"+ioFormat);
           }
       });
        menuItemBitClickChange = new JCheckBoxMenuItem("\u70b9\u51fb\u5207\u6362D7-D0\u5217");
        menuItemBitClickChange.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R,InputEvent.CTRL_MASK));
       menuItemBitClickChange.addActionListener(new ActionListener() {          
           @Override
           public void actionPerformed(ActionEvent arg0) {
				boolean state = ((JCheckBoxMenuItem)menuItemBitClickChange).getState();
				//System.out.println("bitclickchanged actionPerformed state:"+state);
				if(state){
					writeProperties(getConfigPropertiesFile(), "bitclick", "true");
				}else{
					writeProperties(getConfigPropertiesFile(), "bitclick", "false");
				}
				//String bitclick = readValue(getConfigPropertiesFile(), "bitclick");
				//if(bitclick != null)
				//	System.out.println("bitclickchanged actionPerformed bitclick:"+bitclick);
           }
       });

        menuItemShiftSwitch = new JCheckBoxMenuItem("\u5173\u95edShift");
        menuItemShiftSwitch.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W,InputEvent.CTRL_MASK));
       menuItemShiftSwitch.addActionListener(new ActionListener() {          
           @Override
           public void actionPerformed(ActionEvent arg0) {
				boolean state = ((JCheckBoxMenuItem)menuItemShiftSwitch).getState();
				//System.out.println("menuItemShiftSwitch actionPerformed state:"+state);
				if(state){
					writeProperties(getConfigPropertiesFile(), "shiftclose", "true");
				}else{
					writeProperties(getConfigPropertiesFile(), "shiftclose", "false");
				}
				//String shiftclose = readValue(getConfigPropertiesFile(), "shiftclose");
				//if(shiftclose != null)
				//	System.out.println("menuItemShiftSwitch actionPerformed shiftclose:"+shiftclose);
           }
       });


	try{
		 File cfgFile = new File(getConfigPropertiesFile());
		 if(!cfgFile.exists()){
			cfgFile.createNewFile();
		 }
	 } catch (IOException e2) {	
		//System.out.println("cfgFile createNewFile e2.toString():"+e2.toString());   	
	}	
	   
	   String ioFormat = readValue(getConfigPropertiesFile(), "ioformat");
	   String bitclick = readValue(getConfigPropertiesFile(), "bitclick");
	   String shiftclose = readValue(getConfigPropertiesFile(), "shiftclose");
	   
	   if(ioFormat == null){
			writeProperties(getConfigPropertiesFile(), "ioformat", "generic");
			ioFormat = readValue(getConfigPropertiesFile(), "ioformat");
/* <-- wangmingdong -1-11-2015 23:19:41 
			if(ioFormat != null)
				System.out.println("ioformat write ioFormat:"+ioFormat);
			else
				System.out.println("ioformat write ioFormat=null");
--> wangmingdong  */
	   }
/* <-- wangmingdong -1-11-2015 23:19:54 
	   else{
			System.out.println("ioformat read ioFormat:"+ioFormat);
	   }
--> wangmingdong  */
	   if(ioFormat != null && ioFormat.equals("DCS")){
			((JCheckBoxMenuItem)menuItemIOFormatDCS).setState(true);
	   }else{
			((JCheckBoxMenuItem)menuItemIOFormatDCS).setState(false);
	   }
	   
	   if(bitclick == null){
			writeProperties(getConfigPropertiesFile(), "bitclick", "false");
			bitclick = readValue(getConfigPropertiesFile(), "bitclick");
/* <-- wangmingdong -1-11-2015 23:20:05 
			if(bitclick != null)
				System.out.println("ioformat write bitclick:"+bitclick);
			else
				System.out.println("ioformat write bitclick=null");
--> wangmingdong  */
	   }
/* <-- wangmingdong -1-11-2015 23:20:10 
	   else{
			System.out.println("bitclick read bitclick:"+bitclick);
	   }
--> wangmingdong  */
	   if(bitclick != null && bitclick.equals("true")){
			((JCheckBoxMenuItem)menuItemBitClickChange).setState(true);
	   }else{
			((JCheckBoxMenuItem)menuItemBitClickChange).setState(false);
	   }
	   
	   if(shiftclose == null){
			writeProperties(getConfigPropertiesFile(), "shiftclose", "false");
			shiftclose = readValue(getConfigPropertiesFile(), "shiftclose");
/* <-- wangmingdong -1-11-2015 23:20:18 
			if(shiftclose != null)
				System.out.println("menuItemShiftSwitch write shiftclose:"+shiftclose);
			else
				System.out.println("menuItemShiftSwitch write shiftclose=null");
--> wangmingdong  */
	   }
/* <-- wangmingdong -1-11-2015 23:20:22 
	   else{
			System.out.println("menuItemShiftSwitch read shiftclose:"+shiftclose);
	   }
--> wangmingdong  */
	   if(shiftclose != null && shiftclose.equals("true")){
			((JCheckBoxMenuItem)menuItemShiftSwitch).setState(true);
	   }else{
			((JCheckBoxMenuItem)menuItemShiftSwitch).setState(false);
	   }

       scrollTabItem = new JCheckBoxMenuItem("\u91cd\u53e0tab");

        scrollTabItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK));

       scrollTabItem.addActionListener(new ActionListener() {
          
           @Override
           public void actionPerformed(ActionEvent arg0) {
              if(pane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT)
                  pane.setTabLayoutPolicy(JTabbedPane.WRAP_TAB_LAYOUT);
              else
                  pane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
           }
       });
      

       componentTabItem = new JCheckBoxMenuItem("\u8bbe\u7f6e\u53ef\u5173\u95ed\u7684tab");
      componentTabItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.CTRL_MASK));
       componentTabItem.addActionListener(new ActionListener() {
          
           @Override
           public void actionPerformed(ActionEvent e) {
              for(int i = 0 ; i < numTab ; i++)
              {
                  if(componentTabItem.isSelected())
                     initTabComponent(i);
                  else
                     pane.setTabComponentAt(i, null);
              }
           }
       });
      

       JMenuItem reSetItem = new JMenuItem("\u91cd\u53e0");
	   reSetItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R,InputEvent.CTRL_MASK));
       reSetItem.addActionListener(new ActionListener() {
          
           @Override
           public void actionPerformed(ActionEvent e) {
              runTest();
           }
       });
      

       JMenu menu = new JMenu("\u9009\u9879");
       menu.add(menuItemIOFormatDCS);
       menu.add(menuItemBitClickChange);
       menu.add(menuItemShiftSwitch);

/* iryun -2014-12-29 21:0:11 */
/* iryun jdj-tieto-2014-12-29 21:10:42 
	menu.setFont(new Font("\u5b8b\u4f53", Font.PLAIN, 14)); 
	menuItemIOFormatDCS.setFont(new Font("\u5b8b\u4f53", Font.PLAIN, 14)); 
	menuItemBitClickChange.setFont(new Font("\u5b8b\u4f53", Font.PLAIN, 14)); 
 iryun jdj-tieto-2014-12-29 21:10:42 */
/* iryun -2014-12-29 21:0:11 */

	   
/* doom 
       menu.add(tabItemBatchProcessing);
 doom */	   
       //menu.add(componentTabItem);
       //menu.add(scrollTabItem);
       //menu.add(reSetItem);
      
       mb.add(menu);
/* -2014-11-26 12:2:59 */
       JMenu aboutMenu = new JMenu("\u5e2e\u52a9");//("\u5173\u4e8e");

       JMenuItem aboutMenuItem = new JMenuItem("\u5173\u4e8e");
       aboutMenu.add(aboutMenuItem);


	aboutMenuItem.addActionListener(new ActionListener() {
	    public void actionPerformed(ActionEvent e) {
			ImageIcon imageIcon = new ImageIcon();
			Image image =Toolkit.getDefaultToolkit().createImage(getClass().getResource("/org/wddsicmd/draw/images/wdtool.png"));
			imageIcon.setImage(image);
		
			String msg = "\u8054\u7cfb\u4eba:  kevin\n\u7535\u8bdd:    186 2188 3929\n\u90ae\u7bb1:    452542798@qq.com";
			JOptionPane.showMessageDialog(Main.this, msg, null, JOptionPane.PLAIN_MESSAGE, imageIcon);					
		}	    
	});

/* iryun -2014-12-29 21:0:18 */
/* iryun jdj-tieto-2014-12-29 21:10:38 
	aboutMenu.setFont(new Font("\u5b8b\u4f53", Font.PLAIN, 14)); 
	aboutMenuItem.setFont(new Font("\u5b8b\u4f53", Font.PLAIN, 14)); 
 iryun jdj-tieto-2014-12-29 21:10:38 */
/* iryun -2014-12-29 21:0:18 */

       mb.add(aboutMenu);
/* -2014-11-26 12:2:59 */

       setJMenuBar(mb);
      
    }

/* <-- wangmingdong -9-4-2014 0:36:03 */
/*
	static public class Row extends JPanel {
		private static final long serialVersionUID = 1234L;

		private boolean promptFlag = false;
		private final int BIT_COUNT=8;
		public JLabel label;
		public JTextField data;
		public JTextField[] dataList;
		
		public JLabel prompt;
		public JLabel[] promptList;
	
		public Row(){
			super();
			
			label=new JLabel(); 
			label.setPreferredSize(new Dimension(30, 30));

			data=new JTextField(); 
			data.setPreferredSize(new Dimension(120, 30));
			data.setHorizontalAlignment(JTextField.CENTER);
			
			dataList=new JTextField[BIT_COUNT];
			add(label); 
			add(data); 

			for(int index = 0; index < dataList.length; index++){
				JTextField jtf =new JTextField(); 
				jtf.setPreferredSize(new Dimension(30, 30));
				jtf.setHorizontalAlignment(JTextField.CENTER);		
				add(jtf);		
				
				dataList[index] = jtf;
			}

		}

		public Row(boolean flag){

			super();

			promptFlag = flag;
			if(!flag){
				label=new JLabel(); 
				label.setPreferredSize(new Dimension(30, 30));

				data=new JTextField(); 
				data.setPreferredSize(new Dimension(120, 30));
				data.setHorizontalAlignment(JTextField.CENTER);
				
				dataList=new JTextField[BIT_COUNT];
				add(label); 
				add(data); 

				for(int index = 0; index < dataList.length; index++){
					JTextField jtf =new JTextField(); 
					jtf.setPreferredSize(new Dimension(30, 30));
					jtf.setHorizontalAlignment(JTextField.CENTER);		
					add(jtf);		
					
					dataList[index] = jtf;
				}				
			}else{
				label=new JLabel("\u5e8f\u53f7"); 
				label.setPreferredSize(new Dimension(30, 30));

				prompt=new JLabel("\u5341\u516d\u8fdb\u5236"); 
				prompt.setPreferredSize(new Dimension(120, 30));
				prompt.setHorizontalAlignment(JLabel.CENTER);
				
				promptList=new JLabel[BIT_COUNT];
				add(label); 
				add(prompt); 

				for(int index = 0; index < promptList.length; index++){
					JLabel jtf =new JLabel("D"+(BIT_COUNT - 1 - index)); 
					jtf.setPreferredSize(new Dimension(30, 30));
					jtf.setHorizontalAlignment(JLabel.CENTER);		
					add(jtf);		
					
					promptList[index] = jtf;
				}
			}

		}


		public void dump(){
			
			//System.out.println("Row dump ");
			data.setRequestFocusEnabled(true);
			data.requestFocusInWindow();
		}
	}

*/
    private String getTabName(int index){
	String tabItemName = "tab " + index;
	switch(index){
		case TAB_SINGLE_WRITE:
			tabItemName = getLablesString("tab_lcd_params");
			break;
		case TAB_SINGLE_READ:
			tabItemName = getLablesString("tab_single_read");
			break;
		case TAB_MULTI_WRITE:
			tabItemName = getLablesString("tab_multi_write");
			break;
		case TAB_MULTI_READ:
			tabItemName = getLablesString("tab_multi_read");
			break;
		case TAB_PUSH_IMAGE:
			tabItemName = getLablesString("tab_push_image");
			break;
		case TAB_REMOTE_CONTROL:
			tabItemName = "\u8fdc\u7a0b\u63a7\u5236";
			break;
	}	
	return tabItemName;
    }

    private void ToastShow(String msg){
	TimeDialog d = new TimeDialog();  
	int result = d.showDialog(this, msg, 1);
    }

    private final static String ADB_PATH_WINDOWS = "C:\\adb\\adb.exe";
    private final static String ADB_PATH_LINUX = "adb";
    private static String ADB_PATH = ADB_PATH_WINDOWS;	
    private final static String CMD_FILE = "/sys/bus/platform/drivers/mtkfb/send";
/* mss-2015-7-2 8:29:43 */
    private final static String CMD_FILE_PORCH = "/sys/devices/platform/sublcd/driver/send";	
/* mss-2015-7-2 8:29:43 */
    private final static String CMD_FILE_RECV = "/sys/bus/platform/drivers/mtkfb/recv";
    private final static String CMD_SPLIT= "_";	
    private final static String CMD_PATH_WINDOWS = "C:\\adb\\batchCmd.bat";
    private final static String CMD_PATH_LINUX = "/tmp/batchCmd.sh";
    private static String CMD_PATH = CMD_PATH_WINDOWS;
    private static String LINE_SEPATATOR = System.getProperty("line.separator");
    private final static int FUNC_PUSH = 0;
    private final static int FUNC_PULL = 1;
    private final static int FUNC_DELETE = 2;

    private final static String PC_LOAD_DIR = "C:\\MSS_LCD_PRELOADED";	
	
/* doom 
    private final int SW_DATA_COUNT = 109; // ~ 108
 doom */
    private JTextField swAddress;
    private JTextField swCount;
/* doom 
    private JTextField[] swData = new JTextField[SW_DATA_COUNT];
 doom */
    private JTextArea swBatchArea;
    private JScrollPane swBatchAreaScrollPane; 
    private String swBatchStr = null;
    private JTextArea swRecord;
    private JScrollPane swRecordScrollPane;
    private String swRecordStr = null;
    private JTextArea swResult;
    private JScrollPane swResultScrollPane;
    private String swResultStr = null;
    private JTextArea swError;
    private JScrollPane swErrorScrollPane;
    private String swErrorStr = null;
/* -2014-12-3 18:42:36 */
    private JTextArea swLog;
    private JScrollPane swLogScrollPane;
    private String swLogStr = null;
/* -2014-12-3 18:42:36 */
    private JButton swAddrAdd;
    private JButton swAddrDel;
    private JButton swWrite;
    private JButton swRead;
    private JButton swImport;
    private JButton swExport;
/* mss-2015-7-1 22:57:24 */
    private final static int PORCH_COUNT = 13;
    private HintTextField2[] swPorchList;
    private JLabel[] swPorchNameList;
    private JButton swPorchButton;	
/* mss-2015-7-1 22:57:24 */
/* -2014-12-3 18:41:9 */
    private JButton swLogStartStop;
    private JButton swLogPathSet;
/* -2014-12-3 18:41:9 */
/* doom 
    private JPanel swDataAreaSP;
 doom */
/* wangmingdong
    private JList<Row> swDataList;
    private Vector<Row> swRows;
wangmingdong */
    JScrollPane swDataTablePane;
    JTable swDataTable;
/* -2014-11-26 11:26:41 */
    JScrollPane swAddrTablePane;
    JTable swAddrTable;
/* -2014-11-26 11:26:41 */
    JPanel swPane;
    private JPopupMenu swPopupMenu = null;
    private JMenuItem swMenuitemCopy = null;
    private JMenuItem swMenuitemPaste = null;
    private JMenuItem swMenuitemInsertPrevRow = null;
    private JMenuItem swMenuitemInsertNextRow = null;
    private JMenuItem swMenuitemDelete = null;
    private int swMenuitemCopyRow = 0;

    final int swTableRowCountDefault = 1;
    final int swDataTableRowCountMax = 255;
    final int swAddrTableRowCountMax = 255;
    
/* jdj-tieto-2014-11-26 11:32:59 
    CustomTableModel swDefaultTableModel = null;
 jdj-tieto-2014-11-26 11:32:59 */
    private boolean mBatch = false;
    String[] swAddrColumnNames = {"\u5e8f\u53f7", "\u5730\u5740\u9ad88\u4f4d", "\u5730\u5740\u4f4e8\u4f4d", "D7",
     "D6", "D5", "D4", "D3", "D2","D1","D0", "\u53c2\u6570\u5185\u5bb9", "\u53c2\u6570\u4e2a\u6570", "\u53d1\u9001", "\u8bfb\u53d6"};

    class SWLineData {
        public String[] data = null;
    }
    int[] swCopyList = null; 
    ArrayList<SWLineData> swCopyDataList = null; 
	
    public void setValueAtNoFire(JTable table, Object aValue, int row, int column) {
       /*swDefaultTableModel*/((CustomTableModel)table.getModel()).setValueAtNoFire(aValue, table.convertRowIndexToModel(row),
                              table.convertColumnIndexToModel(column));
	swPane.repaint();
	//((CustomTableModel)table.getModel()).fireTableRowsUpdated(row);
    }
    public void setValueAtNoFireInternal(JTable table, Object aValue, int row, int column) {
       /*swDefaultTableModel*/((CustomTableModel)table.getModel()).setValueAtNoFire(aValue, table.convertRowIndexToModel(row),
                              table.convertColumnIndexToModel(column));
	//swPane.repaint();
    }	
    public void setValueAtLine(JTable table, String[] aValue, int row) {
       /*swDefaultTableModel*/((CustomTableModel)table.getModel()).setValueAtLine(aValue, row);	
	((CustomTableModel)table.getModel()).fireTableRowsUpdated(row, row);
    }
    public void setValueAtLineNoFire(JTable table, String[] aValue, int row) {
       /*swDefaultTableModel*/((CustomTableModel)table.getModel()).setValueAtLine(aValue, row);	
    }
    public Vector getValueAtLine(JTable table, int row){
       return ((CustomTableModel)table.getModel()).getValueAtLine(row);	    
    }	

	public static String binaryString2hexString(String bString)
	{
		if (bString == null || bString.equals("") || bString.length() != 8)
			return null;
		
		StringBuffer tmp = new StringBuffer();
		int iTmp = 0;
		try{
		for (int i = 0; i < bString.length(); i += 4)
		{
			iTmp = 0;
			for (int j = 0; j < 4; j++)
			{
				iTmp += Integer.parseInt(bString.substring(i + j, i + j + 1)) << (4 - j - 1);
			}
			tmp.append(Integer.toHexString(iTmp));
		}
		return tmp.toString();
		}catch(NumberFormatException nfe){
			return null;
		}
	}

	public static String hexString2binaryString(String hexString)
	{
		if (hexString == null)
			return null;		

		//System.out.println("hexString2binaryString 1 hexString.length():"+hexString.length());	
		
		if(hexString.length() == 1){
			hexString = "0" + hexString;
		}
		if (hexString.length() != 2)
			return null;
		String bString = "", tmp;
		try{
		for (int i = 0; i < hexString.length(); i++)
		{
			tmp = "0000"
					+ Integer.toBinaryString(Integer.parseInt(hexString
							.substring(i, i + 1), 16));
			bString += tmp.substring(tmp.length() - 4);
		}
		return bString;
		}catch(NumberFormatException nfe){
			return null;
		}	
	}

	public static boolean isUpperCase(String str){
	      for(int i = 0; i < str.length(); i++){
	           char c = str.charAt(i);
	           if (!Character.isUpperCase(c)){
	                return false;
	           }
	      }
	      return true;
	}

	private void swFireTableCellUpdated(JTable table, int row, int column){
		//System.out.println("swFireTableCellUpdated column:"+column+" row:"+row);	
		
		if(row < 0)
			return;
		String currentValue = (String)table.getValueAt(row, column);
		//System.out.println("swFireTableCellUpdated currentValue:"+currentValue);

/* iryun jdj-tieto-2014-12-29 22:0:43 
		int rightShiftCount = 0;
		if(table != null && table == swAddrTable){
			rightShiftCount = 2;
		}		
 iryun jdj-tieto-2014-12-29 22:0:43 */
		
		if(table == swAddrTable && column == (swAddrColumnNames.length - 1 - 2/*rightShiftCount*/)){
			setAddrTableRowSelection(row);
		}else{

			int shiftCount = 0;
			if(table != null && table == swAddrTable){
				shiftCount = 1;
			}
		
			if(column == 1){ // address 			
				String value = (String)table.getValueAt(row, column);
				if(value != null){
					if(value.length() > 2){
						value = value.substring(value.length() - 2);
						value = value.toUpperCase();
						table.setValueAt((Object)value, row, column);
					} 
					else{
						//System.out.println("swFireTableCellUpdated 1 value:"+value);	
						value = hexString2binaryString(value);
						//System.out.println("swFireTableCellUpdated 2 value:"+value);	
						if(value == null ||(value.length() != 8)){
							setValueAtNoFireInternal(table, (Object)"0", row, column);
							for(int index = 0; index < 8; index++){
								setValueAtNoFireInternal(table, (Object)"0", row, column + 1 + index + shiftCount);
							}	

/* iryun jdj-tieto-2014-12-30 17:48:33 
							setValueAtNoFireInternal(table, (Object)"0", row, column);
 iryun jdj-tieto-2014-12-30 17:48:33 */
						
						}else{
							{
								for(int index = 0; index < 8; index++){
									String data = value.substring(index, index+1);
									data = data.toUpperCase();
									//System.out.println("swFireTableCellUpdated 2 data:"+data);									
									setValueAtNoFireInternal(table, (Object)data, row, column + 1 + index + shiftCount);
								}
							}
							boolean isUpperCase = isUpperCase(currentValue);
							if(!isUpperCase){
								currentValue = currentValue.toUpperCase();
								setValueAtNoFireInternal(table, (Object)currentValue, row, column);
							}
						
						}


						
						swPane.repaint();
						//System.out.println("swFireTableCellUpdated 3 value:"+value);	
						// end handler 
						if(table == swDataTable){
							refreashTableData(swAddrTable);
						}
					}
				}
			}else if(table == swAddrTable && column == 2){ // 8 			
				String value = (String)table.getValueAt(row, column);
				if(value != null){
					if(value.length() > 2){
						value = value.substring(value.length() - 2);
						value = value.toUpperCase();
						table.setValueAt((Object)value, row, column);
					} 
/* iryun -2014-12-30 16:8:37 */
					else{
						value = hexString2binaryString(value);
						//System.out.println("swFireTableCellUpdated 2 value:"+value);	
						if(value == null ||(value.length() != 8)){
							table.setValueAt((Object)"0", row, column);			
						}else{
							boolean isUpperCase = isUpperCase(currentValue);
							if(!isUpperCase){
								currentValue = currentValue.toUpperCase();
								setValueAtNoFireInternal(table, (Object)currentValue, row, column);
							}
						}
					}


					
/* iryun -2014-12-30 16:8:37 */
/* iryun jdj-tieto-2014-12-30 16:0:30 
					else
					{
						//System.out.println("swFireTableCellUpdated 1 value:"+value);	
						value = hexString2binaryString(value);
						//System.out.println("swFireTableCellUpdated 2 value:"+value);	
						if(value == null ||(value.length() != 8)){
							setValueAtNoFireInternal(table, (Object)"0", row, column);
							for(int index = 0; index < 8; index++){
								setValueAtNoFireInternal(table, (Object)"0", row, column + 1 + index + shiftCount);
							}						
						}else{
							{
								for(int index = 0; index < 8; index++){
									String data = value.substring(index, index+1);
									//System.out.println("swFireTableCellUpdated 2 data:"+data);									
									setValueAtNoFireInternal(table, (Object)data, row, column + 1 + index + shiftCount);
								}
							}
						}
						swPane.repaint();
						//System.out.println("swFireTableCellUpdated 3 value:"+value);	
						// end handler 
						if(table == swDataTable){
							refreashTableData(swAddrTable);
						}
					}
 iryun jdj-tieto-2014-12-30 16:0:30 */
				}
			}else if(column >= (2+shiftCount) && column <= (9+shiftCount)){ // 8 bit data 
				String value = (String)table.getValueAt(row, column);
				if(value != null){
					if(value.length() > 1){
						value = value.substring(value.length() - 1);
						//System.out.println("swFireTableCellUpdated 11 value:"+value);
						value = value.toUpperCase();
						table.setValueAt((Object)value , row, column);
					}else if(!value.equals("0") && !value.equals("1")){
						table.setValueAt((Object)"0" , row, column);
					}else{
						//System.out.println("swFireTableCellUpdated 12 value:"+value);
						value = "";
						for(int index = 0; index < 8; index++){
							String data = (String)table.getValueAt(row, 2 + shiftCount + index);														
							value += data;
						}					
						//System.out.println("swFireTableCellUpdated 13 value:"+value);	
						value = binaryString2hexString(value);
						//System.out.println("swFireTableCellUpdated 14 value:"+value);	
						String value1 = (String)table.getValueAt(row, 1);
						if(value == null){
	//						if(value1 != null && !value1.equals(""))
							setValueAtNoFire(table, (Object)"0", row, 1);						
						}else{
	//						if(value1 != null && !value1.equals(value))
							value = value.toUpperCase();
							setValueAtNoFire(table, (Object)value, row, 1);	
						}
						//System.out.println("swFireTableCellUpdated 15 value:"+value);	
						// end handler 
						if(table == swDataTable){
							refreashTableData(swAddrTable);
						}				
					}		
				}

			}
		}
	}

/* -2014-11-26 11:27:28 */
	private void refreashTableData(JTable table){
		if(table == swDataTable){
			// update swDataTable
			//System.out.println("@@@ refreashTableData swDataTable");	
			int selectedCount = swAddrTable.getSelectedRowCount();
			if(selectedCount == 1){
				int index = swAddrTable.getSelectedRow();
				String dataStr = (String)swAddrTable.getValueAt(index, swAddrColumnNames.length - 2 - 2/*rightShiftCount*/);
				String countStr = (String)swAddrTable.getValueAt(index, swAddrColumnNames.length - 1 - 2/*rightShiftCount*/);
				
				//System.out.println("@@@ refreashTableData swDataTable dataStr:"+dataStr);	
				//System.out.println("@@@ refreashTableData swDataTable countStr:"+countStr);
				int count = 0;
				int rowCount = swDataTable.getRowCount();
				try{
					count = Integer.parseInt(countStr);
				} catch (Exception ep) {
				}	
				if(count != rowCount){
					if(count > 0 && count <= swDataTableRowCountMax){
						//System.out.println("@@@ refreashTableData error 1");	
						swCreateDataTable(count);
						refreashTableData(swAddrTable);
					}else{
						//System.out.println("@@@ refreashTableData error 2");	
						swCreateDataTable(1);
						refreashTableData(swAddrTable);
					}
				}else{
					String[] dataList = null;
					if(dataStr != null){
						dataList = dataStr.split(",");
					}
					if(dataList != null && dataList.length == count){						
						//System.out.println("@@@ refreashTableData right");
						for(int i = 0; i < count; i++){
							//setValueAtNoFireInternal(swDataTable, (Object)dataList[i], i, 1);
							String value = dataList[i];
							if(value.length() > 2){
								if(value.length() == 3){
									value = value.substring(value.length() - 1);	
								}else{
									value = value.substring(value.length() - 2);	
								}
							}
							String displayValue = value;
							{
								//System.out.println("refreashTableData 1 value:"+value);	
								value = hexString2binaryString(value);
								//System.out.println("refreashTableData 2 value:"+value);	
								if(value == null || (value.length() != 8)){
									setValueAtNoFireInternal(swDataTable, (Object)"0", i, 1);
									for(int di = 0; di < 8; di++){
										setValueAtNoFireInternal(swDataTable, (Object)"0", i, 1 + 1 + di);
									}						
								}else{
									setValueAtNoFireInternal(swDataTable, (Object)displayValue, i, 1);
									{
										for(int di2 = 0; di2 < 8; di2++){
											String data = value.substring(di2, di2+1);
											//System.out.println("refreashTableData 2 data:"+data);									
											setValueAtNoFireInternal(swDataTable, (Object)data, i, 1 + 1 + di2);
										}
									}
								}
								swPane.repaint();

							}
						}						
					}else{
						if(count > 0 && count <= swDataTableRowCountMax){
							//System.out.println("@@@ refreashTableData error 3");	
							swCreateDataTable(count);
							refreashTableData(swAddrTable);
						}
						else{
							//System.out.println("@@@ refreashTableData error 4");	
							swCreateDataTable(1);
							refreashTableData(swAddrTable);
						}
					}
				}
			}
		}
  		else if(table == swAddrTable){
			// update parameter column
			//System.out.println("@@@ refreashTableData swAddrTable");
			int selectedCount = swAddrTable.getSelectedRowCount();
			if(selectedCount == 1){	
				int rowItem = swAddrTable.getSelectedRow();
				int rowCount = swDataTable.getRowCount();
				String dataStr = "";
				for(int index = 0; index < rowCount; index++){
					String value = (String)swDataTable.getValueAt(index, 1);
					if(value.length() == 1){
						value = "0" + value;
					}					
					value = "0x" + value;
					if(index == 0)
						dataStr += value;
					else
						dataStr += "," + value;
				}
				//System.out.println("@@@ refreashTableData swAddrTable dataStr:"+dataStr);

				setValueAtNoFire(swAddrTable, (Object)dataStr, rowItem, swAddrColumnNames.length - 2 - 2/*rightShiftCount*/);
			}
		}
	}

	 public static void HideColumn(JTable table, int column) {
	    TableColumn tc = table.getTableHeader().getColumnModel().getColumn(column);
	    tc.setMaxWidth(0);
	    tc.setPreferredWidth(0);
	    tc.setWidth(0);
	    tc.setMinWidth(0);
	    table.getTableHeader().getColumnModel().getColumn(column).setMaxWidth(0);
	    table.getTableHeader().getColumnModel().getColumn(column).setMinWidth(0);
	}

	public static void showColumn(JTable table, int column, int width) {
	    TableColumn tc = table.getColumnModel().getColumn(column);
	    tc.setMaxWidth(width);
	    tc.setPreferredWidth(width);
	    tc.setWidth(width);
	    tc.setMinWidth(width);
	    table.getTableHeader().getColumnModel().getColumn(column).setMaxWidth(width);
	    table.getTableHeader().getColumnModel().getColumn(column).setMinWidth(width);
	}

	private class CustomTableCellRenderer extends DefaultTableCellRenderer {
	    private static final long serialVersionUID = 1L;

	    @Override
	    public Component getTableCellRendererComponent(JTable table,
	            Object value, boolean isSelected, boolean hasFocus, int row,
	            int column) {
	        Component c = super.getTableCellRendererComponent(table, value,
	                isSelected, hasFocus, row, column);

		//System.out.println("getTableCellRendererComponent row:"+row+" column:"+column+" value:"+value);
		//System.out.println("getTableCellRendererComponent c:"+c);	
		int shiftCount = 0;
		if(table != null && table == swAddrTable){
			shiftCount = 1;
		}
		
		if(column >= (2+shiftCount) && column <= (9+shiftCount)
			&& value != null && value.equals("1")){
			setForeground(Color.RED);
		}else{
			setForeground(Color.BLACK);
		}
/* jdj-tieto-2014-12-3 17:44:24 
		setDocument(new ClearDocument());
 jdj-tieto-2014-12-3 17:44:24 */
			
	        return c;
	    }
	}

/* iryun -2014-12-29 11:7:41 */

	private void swAddrTableCopyHandler(){

		int allCount = swAddrTable.getRowCount();
		int count = swAddrTable.getSelectedRowCount();
		if(allCount > 0 && count > 0){
			swCopyList = swAddrTable.getSelectedRows();
			if(swCopyList != null && swCopyList.length > 0){
				swCopyDataList = new ArrayList<SWLineData>();
				for(int index = 0; index < swCopyList.length; index++){
					Vector v = getValueAtLine(swAddrTable, swCopyList[index]);
					String[] vStr = new String[v.size()];
					for(int i = 0; i < v.size(); i++){
						vStr[i] = (String)v.get(i);
						//System.out.println("swAddrTableCopyHandler i:"+i+" v.get(i):"+v.get(i));	
					}
					SWLineData lineData = new SWLineData();
					lineData.data = vStr;
					swCopyDataList.add(lineData);
				}
										
				ToastShow("\u590d\u5236\u6210\u529f\uff01");
					
				return;
/* <-- wangmingdong -1-11-2015 20:45:03 
				boolean ioFormatDCS = ioFormatDCSSelected();
				String dataStr = null;
				String dataListStr = "";
				for(int index = 0; index < list.length; index++){
					dataStr = LineExport(ioFormatDCS, list[index]);
					if(dataStr != null){
						dataListStr += dataStr + "\n";
					}	
				}
				swRecord.setText(dataListStr);
--> wangmingdong  */
			}
		}	
		swCopyList = null;
		swCopyDataList = null;
		
		ToastShow("\u590d\u5236\u5931\u8d25\uff01");
	}
	private void swAddrTablePasteHandler(){
		if(swCopyList != null && swCopyList.length > 0){
			int allCount = swAddrTable.getRowCount();
			int count = swAddrTable.getSelectedRowCount();	
			if(swCopyList.length == count
				&& swCopyDataList != null && swCopyDataList.size() == count){
				int[] list = swAddrTable.getSelectedRows();
				if(list != null && list.length > 0){
					for(int index = 0; index < list.length; index++){
						Vector v = getValueAtLine(swAddrTable, list[index]);
						swCopyDataList.get(index).data[0] = (String)v.get(0);
						setValueAtLineNoFire(swAddrTable, swCopyDataList.get(index).data, list[index]);
					}
				}
				//System.out.println("swAddrTablePasteHandler swCopyDataList.size():"+swCopyDataList.size());	
				
				swCopyList = null;
				swCopyDataList = null;	

				refreashTableData(swDataTable);
				swPane.repaint();

				ToastShow("\u7c98\u8d34\u6210\u529f\uff01");
				
				return;
			}
		}
		swCopyList = null;
		swCopyDataList = null;		
		
		ToastShow("\u7c98\u8d34\u5931\u8d25\uff01");
	}

	public class AddrTableDoubleClick2 extends MouseAdapter {
	 Timer mouseTimer = null;
	 public void mouseClicked(MouseEvent e)
	 {
		
		int row =((JTable)e.getSource()).rowAtPoint(e.getPoint());
		int column=((JTable)e.getSource()).columnAtPoint(e.getPoint());


		if(SwingUtilities.isRightMouseButton (e) )
		{
			
			swPopupMenu = new JPopupMenu();
			swMenuitemCopy = new JMenuItem("\u590d\u5236\u9009\u4e2d\u884c");
			swMenuitemPaste = new JMenuItem("\u7c98\u8d34\u9009\u4e2d\u884c");
			swMenuitemInsertPrevRow = new JMenuItem("\u63d2\u5165\u81f3\u9009\u4e2d\u884c\u4e4b\u524d");
			swMenuitemInsertNextRow = new JMenuItem("\u63d2\u5165\u81f3\u9009\u4e2d\u884c\u4e4b\u540e");
			swMenuitemDelete = new JMenuItem("\u5220\u9664\u9009\u4e2d\u884c");

			swMenuitemCopy.addActionListener(new ActionListener(){
		                @Override
				public void actionPerformed(ActionEvent e){
					swAddrTableCopyHandler();
				}
			});
			swMenuitemPaste.addActionListener(new ActionListener(){
		                @Override
				public void actionPerformed(ActionEvent e){
					swAddrTablePasteHandler();
				}
			});			
			swMenuitemInsertPrevRow.addActionListener(new ActionListener(){
		                @Override
				public void actionPerformed(ActionEvent e){
					AddrAddHandler(mBatch, true);	
				}
			});
			swMenuitemInsertNextRow.addActionListener(new ActionListener(){
		                @Override
				public void actionPerformed(ActionEvent e){
					AddrAddHandler(mBatch, false);	
				}
			});			
			swMenuitemDelete.addActionListener(new ActionListener(){
		                @Override
				public void actionPerformed(ActionEvent e){
					AddrDelHandler(mBatch);	
				}
			});
										
			swPopupMenu.add(swMenuitemCopy);		
			swPopupMenu.add(swMenuitemPaste);	
			swPopupMenu.add(swMenuitemInsertPrevRow);	
			swPopupMenu.add(swMenuitemInsertNextRow);	
			swPopupMenu.add(swMenuitemDelete);		


			swPopupMenu.show(e.getComponent(), e.getX(), e.getY());
			return;
		}else
		{
			if(!SwingUtilities.isLeftMouseButton (e) ) {
				return;
			}
		}
		
		//System.out.println("@@@ mouseClicked row:"+row+" column:"+column);	
		if(!(((column >= (2+1) && column <= (9+1)) ||column == (swAddrColumnNames.length-1) 
			|| column == (swAddrColumnNames.length - 2)) && row >= 0)){
			return;
		}
		
		boolean bitclick = bitClickChangedSelected();
	  	if(bitclick){
			if(e.getClickCount() == 1){
				 row =((JTable)e.getSource()).rowAtPoint(e.getPoint());
				 column=((JTable)e.getSource()).columnAtPoint(e.getPoint());
				 if(row >= 0){
					//System.out.println("@@@ mouseClicked row:"+row+" column:"+column);	
					if(column >= (2+1) && column <= (9+1) ){
						String value = (String)swAddrTable.getValueAt(row, column);
						if(value != null)
						swAddrTable.setValueAt((Object)(value.equals("0") ? "1" : "0") , row, column);
						//swFireTableCellUpdated(row, column, true);
					}else{
						//System.out.println("bitclick SingleClicked last 2");
						if(column == (swAddrColumnNames.length-2)){
							AddrTableWriteHandler(row);
						}else if(column == (swAddrColumnNames.length-1)){

						}
					}
				 }
			}
		} 
		else {	
			  //System.out.println("mouseClicked e.getClickCount():"+e.getClickCount());
			  //if (e.getClickCount() == 1)
			  {
			  	   if(mouseTimer != null && mouseTimer.isRunning()){
					   mouseTimer.stop();
					   //System.out.println("DoubleClicked");

					 row =((JTable)e.getSource()).rowAtPoint(e.getPoint());
					 column=((JTable)e.getSource()).columnAtPoint(e.getPoint());
					if(row >= 0){
						if(column >= (2+1) && column <= (9+1) ){
							String value = (String)swAddrTable.getValueAt(row, column);
							if(value != null)
							swAddrTable.setValueAt((Object)(value.equals("0") ? "1" : "0") , row, column);

						}else{
							//System.out.println("! bitclick DoubleClicked last 2");		
							if(column == (swAddrColumnNames.length-2)){
								AddrTableWriteHandler(row);
							}else if(column == (swAddrColumnNames.length-1)){

							}					
						}
					}
			  	   }else{
					   ActionListener taskPerformer = new ActionListener() 
					   {
						    public void actionPerformed(ActionEvent evt)
					            {
						             //System.out.println("SingleClicked");
						             mouseTimer.stop();

								
					            }
					   };
					   mouseTimer = new Timer(600, taskPerformer);
					   mouseTimer.restart(); 
			  	   }
			  }
/* iryun jdj-tieto-2014-12-29 11:27:18 
			  else if(e.getClickCount() == 2 && mouseTimer.isRunning())
			  {
				   mouseTimer.stop();
				   System.out.println("DoubleClicked");

				int row =((JTable)e.getSource()).rowAtPoint(e.getPoint());
				int column=((JTable)e.getSource()).columnAtPoint(e.getPoint());

				if(column >= 2 && column <= 9 && row >= 0){
					String value = (String)swAddrTable.getValueAt(row, column);
					if(value != null)
					swAddrTable.setValueAt((Object)(value.equals("0") ? "1" : "0") , row, column);

				}				   
			  }
 iryun jdj-tieto-2014-12-29 11:27:18 */
		}
	 }
/* iryun jdj-tieto-2014-12-30 16:13:24 
	 public void mousePressed(MouseEvent e)
	    {
	  if(e.getModifiers()==InputEvent.BUTTON3_MASK)
	  {
	   System.out.println("\u4f60\u6309\u4e0b\u7684\u662f\u53f3\u952e\uff01");
	  } 
	  else if(e.getModifiers()==InputEvent.BUTTON2_MASK)
	  {
	   System.out.println("\u4f60\u6309\u4e0b\u7684\u662f\u4e2d\u95f4\u952e\uff01");
	  }
	  else if(e.getModifiers()==InputEvent.BUTTON1_MASK)
	  {
	   System.out.println("\u4f60\u6309\u4e0b\u7684\u662f\u5de6\u952e\uff01");
	  }
	    }
 iryun jdj-tieto-2014-12-30 16:13:24 */
	}

	public class DataTableDoubleClick2 extends MouseAdapter {
	 Timer mouseTimer = null;
	 public void mouseClicked(MouseEvent e)
	 {
		int row =((JTable)e.getSource()).rowAtPoint(e.getPoint());
		int column=((JTable)e.getSource()).columnAtPoint(e.getPoint());
		//System.out.println("@@@ mouseClicked row:"+row+" column:"+column);	
		if(!(column >= 2 && row >= 0)){
			return;
		}
		
		boolean bitclick = bitClickChangedSelected();
	  	if(bitclick){
			if(e.getClickCount() == 1){
						 row =((JTable)e.getSource()).rowAtPoint(e.getPoint());
						 column=((JTable)e.getSource()).columnAtPoint(e.getPoint());
						//System.out.println("@@@ mouseClicked row:"+row+" column:"+column);	
						if(column >= 2 && row >= 0){
							String value = (String)swDataTable.getValueAt(row, column);
							if(value != null)
							swDataTable.setValueAt((Object)(value.equals("0") ? "1" : "0") , row, column);
						}
			}
		} 
		else {	
			  //System.out.println("mouseClicked e.getClickCount():"+e.getClickCount());
			  //if (e.getClickCount() == 1)
			  {
			  	   if(mouseTimer != null && mouseTimer.isRunning()){
					   mouseTimer.stop();
					   //System.out.println("DoubleClicked");

						 row =((JTable)e.getSource()).rowAtPoint(e.getPoint());
						 column=((JTable)e.getSource()).columnAtPoint(e.getPoint());
						//System.out.println("@@@ mouseClicked row:"+row+" column:"+column);	
						if(column >= 2 && row >= 0){
							String value = (String)swDataTable.getValueAt(row, column);
							if(value != null)
							swDataTable.setValueAt((Object)(value.equals("0") ? "1" : "0") , row, column);
						}				
			  	   }else{
					   ActionListener taskPerformer = new ActionListener() 
					   {
						    public void actionPerformed(ActionEvent evt)
					            {
						             //System.out.println("SingleClicked");
						             mouseTimer.stop();
					            }
					   };
					   mouseTimer = new Timer(600, taskPerformer);
					   mouseTimer.restart(); 
			  	   }
			  }
/* iryun jdj-tieto-2014-12-29 11:27:18 
			  else if(e.getClickCount() == 2 && mouseTimer.isRunning())
			  {
				   mouseTimer.stop();
				   System.out.println("DoubleClicked");

				int row =((JTable)e.getSource()).rowAtPoint(e.getPoint());
				int column=((JTable)e.getSource()).columnAtPoint(e.getPoint());

				if(column >= 2 && column <= 9 && row >= 0){
					String value = (String)swAddrTable.getValueAt(row, column);
					if(value != null)
					swAddrTable.setValueAt((Object)(value.equals("0") ? "1" : "0") , row, column);

				}				   
			  }
 iryun jdj-tieto-2014-12-29 11:27:18 */
		}
	 }
/* iryun jdj-tieto-2014-12-30 16:13:31 
	 public void mousePressed(MouseEvent e)
	    {
	  if(e.getModifiers()==InputEvent.BUTTON3_MASK)
	  {
	   System.out.println("\u4f60\u6309\u4e0b\u7684\u662f\u53f3\u952e\uff01");
	  } 
	  else if(e.getModifiers()==InputEvent.BUTTON2_MASK)
	  {
	   System.out.println("\u4f60\u6309\u4e0b\u7684\u662f\u4e2d\u95f4\u952e\uff01");
	  }
	  else if(e.getModifiers()==InputEvent.BUTTON1_MASK)
	  {
	   System.out.println("\u4f60\u6309\u4e0b\u7684\u662f\u5de6\u952e\uff01");
	  }
	    }
 iryun jdj-tieto-2014-12-30 16:13:31 */
	}

/* iryun -2014-12-29 11:7:41 */

		private void swCreateAddrTable(int rowCount){

			if(rowCount < 1)
				return;

			int columnCount = swAddrColumnNames.length;
			String[][] rowData = new String[rowCount][columnCount];
			int selectedItem = 0;
			
			if(swAddrTable == null){
				for(int index = 0; index < rowCount; index++){
					rowData[index][0] = "\u5730\u5740" + (index + 1);
					for(int j = 1; j < columnCount; j++){
						if(j == (columnCount - 1)){
							rowData[index][j] = "\u2193";
						}else if(j == (columnCount - 2)){
							rowData[index][j] = "\u2191";
						}else if(j == (columnCount - 1 - 2/*rightShiftCount*/)){
							rowData[index][j] = "1";
						}else if(j == (columnCount - 2 - 2/*rightShiftCount*/)
						|| j == 1 || j == 2){
							rowData[index][j] = "00";
						}else{
							rowData[index][j] = "0";
						}				
					}
				}
			}else{
				for(int rowItem = 0; rowItem < rowCount; rowItem++){
					rowData[rowItem][0] = "\u5730\u5740" + (rowItem + 1);
					for(int colItem = 1; colItem < columnCount; colItem++){
						rowData[rowItem][colItem] = (String)swAddrTable.getValueAt(rowItem, colItem);				
					}
				}
				selectedItem = swAddrTable.getSelectedRow();
			}

			CustomTableModel swDefaultTableModel = new CustomTableModel(rowData,swAddrColumnNames)
			{
				
				public boolean isCellEditable(int rowindex,int colindex){
					if (colindex==0) return false;   
					else if(colindex >= (2+1) && colindex <= (9+1)) return false;
					else if(colindex == (swAddrColumnNames.length-1) || colindex == (swAddrColumnNames.length - 2)) return false;
					else return true;                     
				}
/* iryun jdj-tieto-2014-12-29 11:46:30 
				public void fireTableCellUpdated(int row, int column) {
				    fireTableChanged(new TableModelEvent(this, row, row, column));
					swFireTableCellUpdated(row, column);
				}			
				public void setValueAtNoFire(Object aValue, int row, int column) {
				    Vector rowVector = (Vector)dataVector.elementAt(row);
				    rowVector.setElementAt(aValue, column);
				}				
 iryun jdj-tieto-2014-12-29 11:46:30 */
			};
			swDefaultTableModel.setFireTableCellUpdatedListener(new CustomTableModel.FireTableCellUpdatedListener(){
				@Override
				public void onFireTableCellUpdated(int row, int column){
					swFireTableCellUpdated(swAddrTable, row, column);
				}
			});
					
			swAddrTable = new JTable ((DefaultTableModel)swDefaultTableModel);	
			DefaultTableCellRenderer tcr = new CustomTableCellRenderer();
			 tcr.setHorizontalAlignment(JLabel.CENTER);
			//tcr.setHorizontalAlignment(SwingConstants.CENTER);
			swAddrTable.setDefaultRenderer(Object.class, tcr);		
			//swDataTable.setPreferredScrollableViewportSize(new Dimension(600, 100));//
			swAddrTable.setRowHeight (20);//
			//swDataTable.setRowHeight (0, 20);//
			swAddrTable.setRowMargin (5);//
			swAddrTable.setRowSelectionAllowed (true);//
			//swDataTable.setSelectionBackground (Color.white);//
			//swDataTable.setSelectionForeground (Color.red);//
			//swDataTable.setGridColor (Color.black);//
			swAddrTable.selectAll ();//
			swAddrTable.clearSelection ();//
			swAddrTable.setDragEnabled (false);//
			swAddrTable.setShowGrid (false);//
			swAddrTable.setShowHorizontalLines (true);//
			swAddrTable.setShowVerticalLines (true);//
			//swDataTable.setValueAt ("tt", 0, 0);//
			swAddrTable.doLayout ();
			//iends.setBackground (Color.lightGray);
			//swDataTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);//AUTO_RESIZE_OFF);
			 swAddrTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);

	 
			TableColumn column = null;

			for(int index = 0; index < columnCount; index++){
				column = swAddrTable.getColumnModel().getColumn(index);
				if(index == 1
/* iryun -2014-12-29 21:43:32 */
					||index == 2 
/* iryun -2014-12-29 21:43:32 */
				){
					column.setPreferredWidth(70); 
				}
				else if(index  == (columnCount - 2) || index == (columnCount - 1)){
					column.setPreferredWidth(50); 				
				}
				else if(index == (columnCount - 2 - 2/*rightShiftCount*/)){
					HideColumn(swAddrTable, index);
					//showColumn(swAddrTable, index, 50);
				}
				else if(index == 0 ||index == (columnCount - 1 - 2/*rightShiftCount*/))
					column.setPreferredWidth(60); 				
				else
					column.setPreferredWidth(25); 
			}
			
			swAddrTablePane.setViewportView(swAddrTable);

			swAddrTable.getSelectionModel().addListSelectionListener(
			        new ListSelectionListener()
			        {
			             public void valueChanged(ListSelectionEvent e)
			             {
						//System.out.println("swAddrTable valueChanged");
						//System.out.println("swAddrTable valueChanged e.getFirstIndex():"+e.getFirstIndex());
						//System.out.println("swAddrTable valueChanged e.getLastIndex():"+e.getLastIndex());
						int count = swAddrTable.getSelectedRowCount();
						//System.out.println("swAddrTable valueChanged count:"+count);
						if(count == 1){
							int row = swAddrTable.getSelectedRow();
							//System.out.println("swAddrTable valueChanged row:"+row);
							setAddrTableRowSelection(row);						
							swDataTable.setVisible(true);
						}else {					
							swDataTable.setVisible(false);
						}

			             }
			        }            
			);

			swAddrTable.addMouseListener(new AddrTableDoubleClick2());

	/* -2014-11-26 13:51:9 */
				setAddrTableRowSelection(selectedItem);
	/* -2014-11-26 13:51:9 */

		}
	/* -2014-11-26 11:27:28 */
		
		private void swCreateDataTable(int rowCount){

			if(rowCount < 1)
				return;

			String[] columnNames = {"\u5e8f\u53f7", "\u53c2\u657016\u8fdb\u5236", "D7",
			 "D6", "D5", "D4", "D3", "D2","D1","D0"};
			int columnCount = columnNames.length;
			String[][] rowData = new String[rowCount][columnCount];
			
			for(int index = 0; index < rowCount; index++){
				rowData[index][0] = "\u53c2\u6570" + (index + 1);
				for(int j = 1; j < columnCount; j++)
				rowData[index][j] = "0";
			}

			CustomTableModel swDefaultTableModel = new CustomTableModel(rowData,columnNames)
			{
				
				public boolean isCellEditable(int rowindex,int colindex){
					if (colindex==0) return false;   
					else if(colindex >= 2 && colindex <= 9) return false;
					else return true;                     
				}
/* iryun jdj-tieto-2014-12-29 12:2:57 
				public void fireTableCellUpdated(int row, int column) {
				    fireTableChanged(new TableModelEvent(this, row, row, column));
					swFireTableCellUpdated(row, column);
				}			
				public void setValueAtNoFire(Object aValue, int row, int column) {
				    Vector rowVector = (Vector)dataVector.elementAt(row);
				    rowVector.setElementAt(aValue, column);
				}				
 iryun jdj-tieto-2014-12-29 12:2:57 */
			};
			swDefaultTableModel.setFireTableCellUpdatedListener(new CustomTableModel.FireTableCellUpdatedListener(){
				@Override
				public void onFireTableCellUpdated(int row, int column){
					swFireTableCellUpdated(swDataTable, row, column);
				}
			});
					
			swDataTable = new JTable ((DefaultTableModel)swDefaultTableModel);	
			DefaultTableCellRenderer tcr = new CustomTableCellRenderer();
			 tcr.setHorizontalAlignment(JLabel.CENTER);
			//tcr.setHorizontalAlignment(SwingConstants.CENTER);
			swDataTable.setDefaultRenderer(Object.class, tcr);		
			//swDataTable.setPreferredScrollableViewportSize(new Dimension(600, 100));//
			swDataTable.setRowHeight (20);//
			//swDataTable.setRowHeight (0, 20);//
			swDataTable.setRowMargin (5);//
			swDataTable.setRowSelectionAllowed (true);//
			//swDataTable.setSelectionBackground (Color.white);//
			//swDataTable.setSelectionForeground (Color.red);//
			//swDataTable.setGridColor (Color.black);//
			swDataTable.selectAll ();//
			swDataTable.clearSelection ();//
			swDataTable.setDragEnabled (false);//
			swDataTable.setShowGrid (false);//
			swDataTable.setShowHorizontalLines (true);//
			swDataTable.setShowVerticalLines (true);//
			//swDataTable.setValueAt ("tt", 0, 0);//
			swDataTable.doLayout ();
			//iends.setBackground (Color.lightGray);
			//swDataTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);//AUTO_RESIZE_OFF);
			 swDataTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
	 
			TableColumn column = null;

			for(int index = 0; index < columnCount; index++){
				column = swDataTable.getColumnModel().getColumn(index);
				if(index == 1)
					column.setPreferredWidth(75); 
				else if(index == 0)
					column.setPreferredWidth(50); 				
				else
					column.setPreferredWidth(25); 
			}
			
			swDataTablePane.setViewportView(swDataTable);
	/* wangmingdong
			swDataTable.getSelectionModel().addListSelectionListener(
			        new ListSelectionListener()
			        {
			             public void valueChanged(ListSelectionEvent e)
			             {
						//System.out.println("valueChanged e.getFirstIndex():"+e.getFirstIndex());
						//System.out.println("valueChanged e.getLastIndex():"+e.getLastIndex());
			             }
			        }            
			);
	wangmingdong */
			swDataTable.addMouseListener(new DataTableDoubleClick2());
/* iryun jdj-tieto-2014-12-29 11:59:26 
			swDataTable.addMouseListener(new MouseAdapter()	{ 
				public void mouseClicked(MouseEvent e) 
				{ 
					boolean bitclick = bitClickChangedSelected();
				  	if(e.getClickCount() == 1 && bitclick){
						int row =((JTable)e.getSource()).rowAtPoint(e.getPoint());
						int column=((JTable)e.getSource()).columnAtPoint(e.getPoint());
						//System.out.println("@@@ mouseClicked row:"+row+" column:"+column);	
						if(column >= 2 && row >= 0){
							String value = (String)swDataTable.getValueAt(row, column);
							if(value != null)
							swDataTable.setValueAt((Object)(value.equals("0") ? "1" : "0") , row, column);
						}
					} 
					else 
						return;
					} 
				});
 iryun jdj-tieto-2014-12-29 11:59:26 */


		}

	    public void layoutswPaneChilds(int width, int height){
			int padding = 10;

			int contentWidth = width - padding * 2;
			int contentHeight = height - padding * 2;

			int w = 0;
			int h = 0;

			w = (contentWidth -padding ) / 2;
			h = (contentHeight -padding ) / 2;

/* mss-2015-7-2 8:58:25 */
			int leftW = (contentWidth -padding ) * 22 / (22+13);
			int rightW = (contentWidth -padding ) - leftW;

			w = rightW;
/* mss-2015-7-2 8:58:25 */
			
	/* jdj-tieto-2014-12-4 11:39:19 
			boolean debug = false;
	 jdj-tieto-2014-12-4 11:39:19 */

			boolean log = true;

	/* jdj-tieto-2014-12-4 11:39:21 
			if(debug){
				h /= 2;
				swResultScrollPane.setBounds(new Rectangle(padding * 2 + w, height - h - padding, w, 2 * h / 3));
	    		}
	 jdj-tieto-2014-12-4 11:39:21 */

	/* jdj-tieto-2014-12-4 11:44:47 
			if(log){
				h /= 2;
				swLogScrollPane.setBounds(new Rectangle(padding * 2 + w, height - h - padding, w, 2 * h / 3));
	    		}
	 jdj-tieto-2014-12-4 11:44:47 */

	/* jdj-tieto-2014-12-4 11:39:51 
			if(debug){
				swErrorScrollPane.setBounds(new Rectangle(padding * 2 + w, height - h * 2 - padding, w, h));
			}else 
	 jdj-tieto-2014-12-4 11:39:51 */
	/* jdj-tieto-2014-12-4 11:44:43 
			if(log){
				swErrorScrollPane.setBounds(new Rectangle(padding * 2 + w, height - h * 2 - padding, w, h));
			}else
			{
				swErrorScrollPane.setBounds(new Rectangle(padding * 2 + w, height - h  - padding, w,  7 * h / 8));
			}
	 jdj-tieto-2014-12-4 11:44:43 */
	/* jdj-tieto-2014-12-4 11:39:59 
			if(debug){
				h *= 2;
			}
	 jdj-tieto-2014-12-4 11:39:59 */
	/* jdj-tieto-2014-12-4 11:44:42 
			if(log){
				h *= 2;
			}
	 jdj-tieto-2014-12-4 11:44:42 */

			h /= 8;

			if(log){
				swErrorScrollPane.setBounds(new Rectangle(padding * 2 + leftW, height - 8*h - padding, w, 4*h));
				swLogScrollPane.setBounds(new Rectangle(padding * 2 + leftW, height - 4*h - padding, w, 3*h));
				((HintJTextArea)swLog).setDisplayWidth(w);
				((HintJTextArea)swError).setDisplayWidth(w);
			}else
			{
				swErrorScrollPane.setBounds(new Rectangle(padding * 2 + leftW, height - 8*h  - padding, w,  7 * h));
				((HintJTextArea)swError).setDisplayWidth(w);
			}

			w /= 2;
	/* -2014-12-3 20:14:29 */
			swLogStartStop.setBounds(new Rectangle(padding * 2 +  leftW, height - h - padding, w - 5, h));
			swLogPathSet.setBounds(new Rectangle(padding * 2 + leftW + w  + 5, height - h - padding, w - 5, h));		
	/* -2014-12-3 20:14:29 */

/* mss-2015-7-2 8:59:33 */
			w = leftW;
/* mss-2015-7-2 8:59:33 */
	
			swRecordScrollPane.setBounds(new Rectangle(padding, height - 4 * h - padding - 3*h, w, 3 * h));	
			((HintJTextArea)swRecord).setDisplayWidth(w);

			swImport.setBounds(new Rectangle(padding, height - 4 * h - padding, w/2 - 5, h));
			swExport.setBounds(new Rectangle(padding + w/2 + 5, height - 4 * h - padding, w/2 - 5, h));
			
	/* -2014-11-26 12:0:1 */		
/* iryun jdj-tieto-2014-12-30 13:57:9 
			swWrite.setBounds(new Rectangle(padding, height - 6 * h - padding, w - 5, h));
			swRead.setBounds(new Rectangle(padding + w + 5, height - 6 * h - padding, w - 5, h));
 iryun jdj-tieto-2014-12-30 13:57:9 */

/* mss-2015-7-1 23:29:36 */
			int cellOffset = 0;
			int cellWidth = (w  - (PORCH_COUNT -1)*cellOffset) / (PORCH_COUNT+1);
			for(int index = 0; index < swPorchList.length; index++){		
				int cWidth = cellWidth * 3 / 2;
				if(index == 0 || index == 1){
					swPorchList[index].setBounds(new Rectangle(padding + index * (cWidth + cellOffset), height - 2 * h - padding, cWidth, h));
					swPorchNameList[index].setBounds(new Rectangle(padding + index * (cWidth + cellOffset), height - 3* h - padding, cWidth, h));
				}
				else{
					swPorchList[index].setBounds(new Rectangle(padding +(w  - (PORCH_COUNT -2)*cellWidth) + (index - 2) * (cellWidth + cellOffset), height - 2 * h - padding, cellWidth, h));				
					swPorchNameList[index].setBounds(new Rectangle(padding +(w  - (PORCH_COUNT -2)*cellWidth) + (index - 2) * (cellWidth + cellOffset), height - 3 * h - padding, cellWidth, h));
				}
			}		
			swPorchButton.setBounds(new Rectangle(padding, height - h - padding, w , h));
/* mss-2015-7-1 23:29:36 */

/* mss-2015-7-2 9:5:46 
			w = (contentWidth -padding ) / 2;
			w /= 2;
 mss-2015-7-2 9:5:46 */
			swAddrAdd.setBounds(new Rectangle(padding, height - 8 * h - padding, w/2 - 5, h));
			swAddrDel.setBounds(new Rectangle(padding + w/2 + 5, height - 8 * h - padding, w/2 - 5, h));
	/* -2014-11-26 12:0:1 */
	
			w = (contentWidth -padding ) / 2;
			h = (contentHeight -padding ) / 2;

/* iryun jdj-tieto-2014-12-29 21:20:27 
			int addrWidth = w;
 iryun jdj-tieto-2014-12-29 21:20:27 */
			int addrWidth = (contentWidth -padding ) * 22 / (22+13);
			int dataWidth = (contentWidth -padding ) - addrWidth;
			
			swAddrTablePane.setBounds(new Rectangle(padding, padding, addrWidth, h));	
/* iryun jdj-tieto-2014-12-30 13:57:15 
			swBatchAreaScrollPane.setBounds(new Rectangle(padding, padding, w, h));	
 iryun jdj-tieto-2014-12-30 13:57:15 */

/* iryun jdj-tieto-2014-12-29 21:22:35 
			int topW = w;
 iryun jdj-tieto-2014-12-29 21:22:35 */
/* iryun -2014-12-29 21:21:1 */
			int topW = addrWidth;			
/* iryun -2014-12-29 21:21:1 */
			int topH = h;
			swDataTablePane.setBounds(new Rectangle(topW + padding * 2, padding, dataWidth, h));	
			w = (w -padding ) / 2;
			h = (h -padding * 2) / 4;		
			swAddress.setBounds(new Rectangle(topW + padding * 2 + (topW - w) / 2, padding, w, h));
			swCount.setBounds(new Rectangle(topW + padding * 2, padding * 2 + h, w, h));
			
	/* jdj-tieto-2014-11-26 11:59:16 
			swWrite.setBounds(new Rectangle(topW + padding * 2, padding * 3 + h * 2, w, h * 2));
			swRead.setBounds(new Rectangle(topW + padding * 3 + w, padding * 3 + h * 2, w, h * 2));
	 jdj-tieto-2014-11-26 11:59:16 */
		
	    }

	    private void batchSwtich(boolean batch){
			
/* iryun -2014-12-30 13:58:23 */
		swWrite.setVisible(false);
		swRead.setVisible(false);
/* iryun -2014-12-30 13:58:23 */
			
		if(batch){
			swAddress.setVisible(false);
			swCount.setVisible(false);
			swDataTablePane.setVisible(false);
			swAddrTablePane.setVisible(false);
			
			swBatchAreaScrollPane.setVisible(true);
		}else{
			swAddress.setVisible(false);
			swCount.setVisible(false);
			swDataTablePane.setVisible(true);
			swAddrTablePane.setVisible(true);
			
			swBatchAreaScrollPane.setVisible(false);
		}
	    }

	/* <-- wangmingdong -11-28-2014 2:10:14 
	    private void updateSingleReadInfo(String info){
		
		if(swResult != null){
			swResult.setText(info);
		}
		//System.out.println("updateSingleReadInfo 1 info:"+info);	
		
		String[] infoList = info.split("_");
		if(infoList.length > 3){
			String addressStr = infoList[0];
			String countStr = infoList[1];
			int count = 0;
			try{
				count = Integer.parseInt(countStr);
			} catch (Exception ep) {
			}		
			if(count > 0){
				//System.out.println("updateSingleReadInfo 1 count:"+count);	
				//System.out.println("updateSingleReadInfo 1 swDataTable.getRowCount():"+swDataTable.getRowCount());	

				if(count != swDataTable.getRowCount()){
					swCreateDataTable(count);
				}
				
				swCount.setText(countStr);
				if(count == (infoList.length - 2)){
					for(int row = 0; row < count; row++){
						String dStr = infoList[2 + row];
						setValueAtNoFire(swDataTable, (Object)dStr, row, 1);
						String hexStr = hexString2binaryString(dStr);
						//System.out.println("updateSingleReadInfo 1 dStr:"+dStr);	
						//System.out.println("updateSingleReadInfo 1 hexStr:"+hexStr);	
						if(hexStr.length() == 8){
							for(int index = 0; index < 8; index++){
								String data = hexStr.substring(index, index+1);							
								setValueAtNoFire(swDataTable, (Object)data, row, 2 + index);
							}
						}			
					}
				}
			}
		}
	    }
	--> wangmingdong  */

	    private void setADBPath(){
			String osStr = System.getProperties().getProperty("os.name");
			if(osStr != null && "Linux".equals(osStr)){
				ADB_PATH = ADB_PATH_LINUX;
				LINE_SEPATATOR = "\n";
			}else{
				ADB_PATH = ADB_PATH_WINDOWS;
				LINE_SEPATATOR = "\n";
			}
	    }
		
	    private JPanel createTabContentSingleWrite(){
	       swPane = new JPanel();
		swPane.setLayout(null);
	/* jdj-tieto-2014-11-26 11:8:58 
		swPane.setBorder(BorderFactory.createTitledBorder(getTabName(TAB_SINGLE_WRITE))); 
	 jdj-tieto-2014-11-26 11:8:58 */

	       JLabel label;
	       JButton button;
		JTextField edit;
		JTextArea mtext;

		mtext = new HintJTextArea("\u7a7a\u767d", getLablesString("batch_area_info"));
		mtext.setMargin(new Insets(30, 0, 0, 0));
		swBatchAreaScrollPane = new JScrollPane(mtext);
		swBatchArea = mtext;	
	       swPane.add(swBatchAreaScrollPane);	
		
		mtext = new HintJTextArea("", "\u9884\u89c8");
		mtext.setMargin(new Insets(30, 0, 0, 0));
		swRecordScrollPane = new JScrollPane(mtext);
		//edit.setHorizontalAlignment(JTextField.CENTER);
		swRecord = mtext;	
	       swPane.add(swRecordScrollPane);	
		   
		mtext = new HintJTextArea("\u7a7a\u767d", "\u6807\u51c6\u8f93\u51fa");
		mtext.setMargin(new Insets(30, 0, 0, 0));
		swResultScrollPane = new JScrollPane(mtext);
		swResult = mtext;
	       swPane.add(swResultScrollPane);	
		   
	/* -2014-12-3 18:44:50 */
		mtext = new HintJTextArea("\u7a7a\u767d", "\u5185\u6838\u65e5\u5fd7");
		mtext.setMargin(new Insets(30, 0, 0, 0));
		swLogScrollPane = new JScrollPane(mtext);
		swLog = mtext;
	       swPane.add(swLogScrollPane);	
	/* -2014-12-3 18:44:50 */

		 mtext = new HintJTextArea("\u7a7a\u767d", "\u9519\u8bef\u8f93\u51fa");
		 mtext.setMargin(new Insets(30, 0, 0, 0));
		 swErrorScrollPane = new JScrollPane(mtext);
		 swError = mtext;
		 swPane.add(swErrorScrollPane);  

		 swDataTablePane = new JScrollPane ();
	        swDataTablePane.addComponentListener(new ComponentAdapter() {
	            @Override
	            public void componentResized(ComponentEvent e) {
				//System.out.println("swDataTablePane componentResized");
	            		if(swDataTable != null)
				swDataTable.setPreferredSize(swDataTablePane.getSize());					
	            }
	        });	

		//swCreateDataTable(swTableRowCountDefault);// default row count is 5 
		swDataTablePane.setBorder(BorderFactory.createTitledBorder("\u53c2\u6570")); 

		swPane.add(swDataTablePane);	

	/* -2014-11-26 11:26:15 */
		 swAddrTablePane = new JScrollPane ();
	        swAddrTablePane.addComponentListener(new ComponentAdapter() {
	            @Override
	            public void componentResized(ComponentEvent e) {
				//System.out.println("swDataTablePane componentResized");
	            		if(swAddrTable != null)
				swAddrTable.setPreferredSize(swAddrTablePane.getSize());					
	            }
	        });	

		swCreateAddrTable(swTableRowCountDefault);// default row count is 5 
		swAddrTablePane.setBorder(BorderFactory.createTitledBorder("\u5730\u5740")); 

		swPane.add(swAddrTablePane);
	/* -2014-11-26 11:26:15 */

		edit = new HintTextField("\u91cd\u7f6e\u8868\u683c\uff0c\u8bf7\u8f93\u5165\u53c2\u6570\u4e2a\u6570\u5e76\u56de\u8f66");
		edit.setDocument(new IntegerDocument());
		swCount = edit;
		swCount.addKeyListener(new KeyListener() {
			public void keyPressed(KeyEvent e) {
				if (e.getKeyCode() == KeyEvent.VK_ENTER) {
					String swCountStr = swCount.getText();
					//System.out.println("createTabContentSingleWrite swCountStr:"+swCountStr);
					int count = 0;
					try{
						count = Integer.parseInt(swCountStr);
					} catch (Exception ep) {
					}
					if(count > swDataTableRowCountMax){
						count = swDataTableRowCountMax;
					}
					swCreateDataTable(count);
					refreashTableData(swDataTable);
					//swCount.setText("");
					//swPane.repaint();				
				}
			}
			public void keyReleased(KeyEvent e) {
			}
			public void keyTyped(KeyEvent e) {
			}
		});	
		edit.setHorizontalAlignment(JTextField.CENTER);
	       swPane.add(edit);	

		edit = new HintTextField("\u8bf7\u8f93\u5165\u53c2\u6570\u5730\u5740");
		edit.setDocument(new IntegerDocument());
		swAddress = edit;
		edit.setHorizontalAlignment(JTextField.CENTER);
	       swPane.add(edit);		
		
		button = new JButton("\u53d1\u9001");
		swWrite = button;
		button.addActionListener(this);
	       swPane.add(button);

		button = new JButton("\u8bfb\u53d6");
		swRead = button;
		button.addActionListener(this);
	       swPane.add(button);

		button = new JButton("\u65b0\u589e\u5730\u5740");
		swAddrAdd = button;
		button.addActionListener(this);
	       swPane.add(button);

		button = new JButton("\u5220\u9664\u5730\u5740");
		swAddrDel = button;
		button.addActionListener(this);
	       swPane.add(button);

		button = new JButton("\u5bfc\u5165");
		swImport = button;
		button.addActionListener(this);
		   swPane.add(button);

		button = new JButton("\u5bfc\u51fa");
		swExport = button;
		button.addActionListener(this);
		   swPane.add(button);

/* mss-2015-7-1 22:35:8 */
		// add porch
		swPorchList=new HintTextField2[PORCH_COUNT];
		swPorchNameList=new JLabel[PORCH_COUNT];
		String[] swPorchNameLabelList = new String[]{
			"HSA","VSA","MOD","LANE","VSYNC","VBP","VFP","HSYNC","HBP","HFP","div1","div2","div"
		};

		String[] swPorchNameListDefault = new String[]{
			"720","1280","1","4","4","c","f","14","46","46","1","1","19"
		};
		
		for(int index = 0; index < swPorchList.length; index++){
			HintTextField2 jtf =new HintTextField2(swPorchNameLabelList[index]); 
			jtf.setText(swPorchNameListDefault[index]);
			jtf.setHorizontalAlignment(JTextField.CENTER);

			swPane.add(jtf);					
			swPorchList[index] = jtf;

			
			JLabel jl =new JLabel(swPorchNameLabelList[index]); 
			jl.setHorizontalAlignment(JTextField.CENTER);

			swPane.add(jl);					
			swPorchNameList[index] = jl;
		}		

		button = new JButton("LCM\u53c2\u6570\u8bbe\u7f6e");
		swPorchButton = button;
		button.addActionListener(this);
		swPane.add(button);
/* mss-2015-7-1 22:35:8 */

	/* -2014-12-3 20:16:12 */
		button = new JButton("\u5f00\u59cb\u5bfc\u51fa\u5185\u6838\u65e5\u5fd7");
		swLogStartStop = button;
		button.addActionListener(this);
		   swPane.add(button);

		button = new JButton("\u4fdd\u5b58\u5185\u6838\u65e5\u5fd7");
		swLogPathSet = button;
		button.addActionListener(this);
		   swPane.add(button);

	/* -2014-12-3 20:16:12 */

	/* doom */
		batchSwtich(mBatch);
	/* doom */

	/* -2014-12-3 18:54:18 */
	/* jdj-tieto-2014-12-3 21:31:48 
		startLogExport();
	 jdj-tieto-2014-12-3 21:31:48 */
	/* -2014-12-3 18:54:18 */

	       return swPane;
	    }

	    Process swLogProcess = null;
	    private final static String LOG_PATH_WINDOWS = "C:\\adb\\swLog.txt";
	    private final static String LOG_PATH_LINUX = "/tmp/swLog.txt";
	    private static String LOG_PATH = LOG_PATH_WINDOWS;		

	    private void startLogExport(){

		String osStr = System.getProperties().getProperty("os.name");
		if(osStr != null && "Linux".equals(osStr)){
			LOG_PATH = LOG_PATH_LINUX;	
		}else{
			LOG_PATH = LOG_PATH_WINDOWS;	
		}		 		

		swLogProcess = swCMDHandler(" shell cat /proc/kmsg ");

		//swLogProcess = swCMDHandler(" shell cat /proc/kmsg > "+LOG_PATH);
		
		//System.out.println("startLogExport swLogProcess:"+swLogProcess);

		if(runningLogExport()){
			swLogStartStop.setText("\u505c\u6b62\u5bfc\u51fa\u5185\u6838\u65e5\u5fd7");
		}else{
			swLogStartStop.setText("\u5f00\u59cb\u5bfc\u51fa\u5185\u6838\u65e5\u5fd7");
		}	
	    }

	    private void stopLogExport(){
		if(swLogProcess != null){
			swLogProcess.destroy();
			swLogProcess = null;
		}
		if(runningLogExport()){
			swLogStartStop.setText("\u505c\u6b62\u5bfc\u51fa\u5185\u6838\u65e5\u5fd7");
		}else{
			swLogStartStop.setText("\u5f00\u59cb\u5bfc\u51fa\u5185\u6838\u65e5\u5fd7");
		}
		
		//System.out.println("stopLogExport swLogProcess:"+swLogProcess);
	    }

	    private boolean runningLogExport(){
		return (swLogProcess != null) ? true : false;
	    }

	    public static void copyFile(File sourceFile, File targetFile) throws IOException {
	        BufferedInputStream inBuff = null;
	        BufferedOutputStream outBuff = null;
	        try {
	            inBuff = new BufferedInputStream(new FileInputStream(sourceFile));

	            outBuff = new BufferedOutputStream(new FileOutputStream(targetFile));

	            byte[] b = new byte[1024 * 5];
	            int len;
	            while ((len = inBuff.read(b)) != -1) {
	                outBuff.write(b, 0, len);
	            }
	            outBuff.flush();
		     //System.out.println("copyFile successfully");    
	        } finally {
	            if (inBuff != null)
	                inBuff.close();
	            if (outBuff != null)
	                outBuff.close();
		     //System.out.println("copyFile finally");    
	        }
	    }

	    private void saveLogExport(){
		stopLogExport();

		JFileChooser fileChooser = new JFileChooser();        
		fileChooser.setDialogTitle("\u4fdd\u5b58\u65e5\u5fd7\u6587\u4ef6");
		int flag = -1;
		try{    
			flag=fileChooser.showSaveDialog(swPane);   
		}   
		catch(HeadlessException he){   
			//System.out.println("saveLogExport Save File Dialog ERROR!");    
		}   	
		if(flag==JFileChooser.APPROVE_OPTION)   
		{   
			try{
				File f=fileChooser.getSelectedFile();   
				String fileName=f.getAbsolutePath();   
				//System.out.println("saveLogExport fileName:"+fileName);   
				if(!f.exists()){
					//System.out.println("saveLogExport createNewFile "+fileName);   
					f.createNewFile();
				}
				if(f.exists()){
					FileWriter fw =  new FileWriter(f);
					fw.write("");
					fw.close();
				}
					
				File swLogPathFile = new File(LOG_PATH);
				//System.out.println("saveLogExport copyFile init");    
				if(swLogPathFile.exists()
					&& f.exists()){
					
					//System.out.println("saveLogExport copyFile start");    
					copyFile(swLogPathFile, f);
					//System.out.println("saveLogExport copyFile successfully");    
				}
			} catch (IOException e2) {	
				//System.out.println("saveLogExport e2.toString():"+e2.toString());   	

			}	
		}   		
			
	    }
		
	    private boolean swCMDInput = false;
	    private boolean swCMDError = false;
	    private Process swCMDHandler(String cmdStr){
		try {
			 setADBPath();
			//System.out.println("swCMDHandler cmdStr:"+cmdStr);
			  
		       Process process = Runtime.getRuntime().exec(ADB_PATH + cmdStr);  
			   
	/* jdj-tieto-2014-12-3 21:44:43 
		       final BufferedWriter batchOutputStream = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
	 jdj-tieto-2014-12-3 21:44:43 */
		       final BufferedReader batchInputStream = new BufferedReader(new InputStreamReader(process.getInputStream()));
		      final  BufferedReader  batchErrorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
			swCMDInput = false;
			swCMDError = false;
			File swLogPathFile = new File(LOG_PATH);
			if(!swLogPathFile.exists()){
				swLogPathFile.createNewFile();
			}
			FileWriter fw =  new FileWriter(swLogPathFile);
			fw.write("");
			fw.close();
			  
		       new Thread(new Runnable() {
		            String line;
		            public void run() {
		               //System.out.println("swCMDHandler listener batchErrorReader started");

				   //String resultStr = "";
				   
		                try {
		                    while((line=batchErrorReader.readLine()) != null) {
					  if(!swCMDError)
					  	swCMDError = true;
		                       //System.out.println("@@@ Error:" + line);
				          //resultStr = resultStr + line + LINE_SEPATATOR;			        
		                   }
					//System.out.println("swCMDHandler batchErrorReader  resultStr:"+resultStr);

		                } catch (IOException e) {
		                   e.printStackTrace();  
				       //System.out.println("swCMDHandler batchErrorReader e.toString:" + e.toString());
		                }

		            }
		       }).start();								  
		       new Thread(new Runnable() {
		            String line;
		            public void run() {
		               //System.out.println("swCMDHandler listener batchInputStream started");

				   String resultStr = "";
				   String logStr = "";
				   int logRefreshCount = 0;
				   int logRefreshMax = 5;
				   int logCurrentItem = 0;
				   int logAllMax = 1024;
				File swLogPathFile = new File(LOG_PATH);
				boolean export = false;
				if(swLogPathFile.exists()){
					export = true;
				}
				FileWriter fw = null;
				   
		                try {
					if(export)
					fw = new FileWriter(swLogPathFile, true);

		                    while((line=batchInputStream.readLine()) != null) {
						
					  if(!swCMDInput)
					  	swCMDInput = true;
		                       //System.out.println("Input:" + line);
				          resultStr = line + LINE_SEPATATOR;	
							   
	 				if(export && fw != null){
						fw.write(resultStr);
	 				}
					if(logCurrentItem < logAllMax){
						logStr += line + LINE_SEPATATOR;	
						logCurrentItem++;	 	
						if(logRefreshCount < logRefreshMax){	 	
							logRefreshCount++;
						}else{
							int length = logStr.length();
							if(length < 300)
								swLog.setText(logStr);
							else
								swLog.setText(logStr.substring(length - 300));
								
							logRefreshCount = 0;
						}
					}else{
						logStr = line + LINE_SEPATATOR;	
						logCurrentItem = 0;
					}
					//System.out.println("swCMDHandler batchInputStream resultStr:"+resultStr);	        
		                   }
	 				if(export && fw != null){
						fw.close();
						fw = null;
	 				}
					//System.out.println("@@@ swCMDHandler batchInputStream fw:"+fw);	
					swLog.setText(logStr);
		                } catch (IOException e) {
			                try {	                
		 				if(export && fw != null){
							fw.close();
							fw = null;
		 				}
					} catch (IOException e2) {		
					       //System.out.println("@@@ 2 swCMDHandler batchInputStream e.toString:" + e.toString());
					}
					swLog.setText(logStr);
		                   e.printStackTrace();  
				       //System.out.println("@@@ swCMDHandler batchInputStream e.toString:" + e.toString());
		                }

		            }
		       }).start();
	/* jdj-tieto-2014-12-3 21:23:21 
		       new Thread(new Runnable() {
		            final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		            public void run() {
		               System.out.println("swCMDHandler writer started");
		                String line;
		                try {
		                    while ((line =br.readLine()) != null) {
		                       batchOutputStream.write(line + LINE_SEPATATOR);
		                       batchOutputStream.flush();
		                    }
		                } catch (IOException e) {
		                   e.printStackTrace();  
				       System.out.println("swCMDHandler System.in e.toString:" + e.toString());
		                }
		            }
		       }).start();
	 jdj-tieto-2014-12-3 21:23:21 */
	/* jdj-tieto-2014-12-3 19:9:47 
		       int i = process.waitFor();
		       System.out.println("swCMDHandler i=" + i);
	 jdj-tieto-2014-12-3 19:9:47 */
	 		return process;
		   } catch (Exception e) {
		       e.printStackTrace();
		       //System.out.println("swCMDHandler exec e.toString:" + e.toString());
			   return null;
		   }	
	    }

	    private void SingleWriteHandler(){

		String addressString = swAddress.getText();
		//String addressString = (String)swDataTable.getValueAt(0, 1);
		if(!isInteger(addressString)) {
		    JOptionPane.showMessageDialog(this,
		      "\u8f93\u5165\u5730\u5740", null, JOptionPane.ERROR_MESSAGE);				
			return;
		}
		String dataString = "";
		String countString =  swCount.getText() ;
		int count = 0;
		if(countString != null){
			try {
				count = Integer.parseInt(countString); 
			} catch (Exception ei) {
				count = 0;
			}	
		}

		int rowCount = swDataTable.getRowCount();
		if(rowCount != count || rowCount == 0) {
		//if(rowCount != (count + 1) || rowCount == 0) {
		    JOptionPane.showMessageDialog(this,
		      "\u6570\u636e\u4e2a\u6570\u548c\u8868\u683c\u884c\u6570\u4e0d\u5bf9\u5e94", null, JOptionPane.ERROR_MESSAGE);				
			return;
		}
		for(int index = 0; index < rowCount; index++){
			String data = (String)swDataTable.getValueAt(index, 1);
			if(data == null || (data != null && (data.length() != 1  && data.length() != 2))){
			    JOptionPane.showMessageDialog(this,
			      "\u8868\u683c\u6570\u636e\u6709\u8bef\uff0c\u5217\u6570\uff1a "+ index, null, JOptionPane.ERROR_MESSAGE);				
				return;			
			}
			if(data.length() == 1)
				data = "0" + data;
			dataString = dataString + CMD_SPLIT + data; 
		}
	/* doom 
		if(!isInteger(countString))  {
		    JOptionPane.showMessageDialog(this,
		      "\u8f93\u5165\u4e2a\u6570", null, JOptionPane.ERROR_MESSAGE);				
			return;
		}
		int count = 0;
		if(countString != null){
			try {
				count = Integer.parseInt(countString); 
			} catch (Exception ei) {
				count = 0;
			}	
		}
		if(count == 0 || count > (SW_DATA_COUNT - 1)) {
		    JOptionPane.showMessageDialog(this,
		      "\u8f93\u5165\u4e2a\u6570", null, JOptionPane.ERROR_MESSAGE);				
			return;
		}
		for(int index = 0; index < count; index++){
			String str = swData[index].getText();

			
			if(str == null) {
			    JOptionPane.showMessageDialog(this,
			      "\u8f93\u5165\u6570\u636e", null, JOptionPane.ERROR_MESSAGE);				
				return;
			}
			int value = -1;
			try {
				value = Integer.parseInt(str); 
			} catch (Exception ei) {
				value = -1;
			}	

			
			if(value == -1) {
			    JOptionPane.showMessageDialog(this,
			      "\u8f93\u5165\u6570\u636e", null, JOptionPane.ERROR_MESSAGE);				
				return;
			}		

			dataString = dataString + CMD_SPLIT + getValidString(str);
			

		}
	 doom */
		
		String cmdStr = getValidString(addressString) + CMD_SPLIT + getValidString(countString) + dataString;
	/*
		if(swRecordStr == null)
			swRecordStr = "";
		else
			swRecordStr = swRecord.getText();
		swRecordStr = swRecordStr + cmdStr + LINE_SEPATATOR;
		if(swRecord != null){
			swRecord.setText(swRecordStr);
		}
	*/
	/* doom 
		//System.out.println("===========os.name:"+System.getProperties().getProperty("os.name"));
		//System.out.println("===========file.separator:"+System.getProperties().getProperty("file.separator"));	
	 doom */
		String cmdString = null;
		setADBPath();
		cmdString = ADB_PATH+" shell echo " + cmdStr + " > " + CMD_FILE;
				
		//System.out.println("SingleWriteHandler cmdString:"+cmdString);
		//cmdString = ADB_PATH+" shell ls /system";
		//cmdString = ADB_PATH+" shell ls -l " + CMD_FILE;
		//cmdString = ADB_PATH+" shell echo " + CMD_FILE;

		//System.out.println("SingleWriteHandler cmdString:"+cmdString);
		try {
	               Process process = Runtime.getRuntime().exec(cmdString);  
	               final BufferedWriter outputStream = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
	               final BufferedReader inputStream = new BufferedReader(new InputStreamReader(process.getInputStream()));
	              final  BufferedReader  errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
	               new Thread(new Runnable() {
	                    String line;
	                    public void run() {
	                       //System.out.println("SingleWriteHandler listener errorReader started");
				   String line_separator = System.getProperty("line.separator");
	                       //System.out.println("SingleWriteHandler run line_separator:"+line_separator);
						   
				   String resultStr = "";
	                        try {
	                            while((line=errorReader.readLine()) != null) {
	                               //System.out.println(line);
				          resultStr = resultStr + line + line_separator;			        
	                           }
					//System.out.println("SingleWriteHandler errorReader resultStr:"+resultStr);
				      if(swError != null && (resultStr != null && !resultStr.equals(""))){
						swError.setText(resultStr);
				      	}
	                        } catch (IOException e) {
	                           //e.printStackTrace();  
	                        }

	                    }
	               }).start();			  
	               new Thread(new Runnable() {
	                    String line;
	                    public void run() {
	                       //System.out.println("SingleWriteHandler listener started");
				   String line_separator = System.getProperty("line.separator");
	                       //System.out.println("SingleWriteHandler run line_separator:"+line_separator);
						   
				   String resultStr = "";
	                        try {
	                            while((line=inputStream.readLine()) != null) {
	                               //System.out.println(line);
				          resultStr = resultStr + line + line_separator;			        
	                           }
					//System.out.println("SingleWriteHandler run resultStr:"+resultStr);
				      if(swResult != null && (resultStr != null && !resultStr.equals(""))){
						swResult.setText(resultStr);
				      	}
	                        } catch (IOException e) {
	                           //e.printStackTrace();  
	                        }

	                    }
	               }).start();
	               new Thread(new Runnable() {
	                    final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	                    public void run() {
	                       //System.out.println("SingleWriteHandler writer started");
	                        String line;
	                        try {
	                            while ((line =br.readLine()) != null) {
	                               outputStream.write(line + LINE_SEPATATOR);
	                               outputStream.flush();
	                            }
	                        } catch (IOException e) {
	                           //e.printStackTrace();  
	                        }
	                    }
	               }).start();
	               int i = process.waitFor();
	               //System.out.println("SingleWriteHandler i=" + i);
	           } catch (Exception e) {
	               e.printStackTrace();
	           }
	    }

	    private void SingleReadHandler(){

		String addressString = swAddress.getText();
		//String addressString = (String)swDataTable.getValueAt(0, 1);
		if(!isInteger(addressString)) {
		    JOptionPane.showMessageDialog(this,
		      "\u8f93\u5165\u5730\u5740", null, JOptionPane.ERROR_MESSAGE);				
			return;
		}	
	/* doom 
		
		String dataString = "";
		String countString =  swCount.getText() ;
		int count = 0;
		if(countString != null){
			try {
				count = Integer.parseInt(countString); 
			} catch (Exception ei) {
				count = 0;
			}	
		}

		int rowCount = swDataTable.getRowCount();
		if(rowCount != count || rowCount == 0) {
		    JOptionPane.showMessageDialog(this,
		      "\u6570\u636e\u4e2a\u6570\u548c\u8868\u683c\u884c\u6570\u4e0d\u5bf9\u5e94", null, JOptionPane.ERROR_MESSAGE);				
			return;
		}
		for(int index = 0; index < rowCount; index++){
			String data = (String)swDataTable.getValueAt(index, 1);
			if(data == null || (data != null && (data.length() != 1  && data.length() != 2))){
			    JOptionPane.showMessageDialog(this,
			      "\u8868\u683c\u6570\u636e\u6709\u8bef\uff0c\u5217\u6570\uff1a "+ index, null, JOptionPane.ERROR_MESSAGE);				
				return;			
			}
			if(data.length() == 1)
				data = "0" + data;
			dataString = dataString + CMD_SPLIT + data; 
		}
	 doom */
	/* doom 
		if(!isInteger(countString))  {
		    JOptionPane.showMessageDialog(this,
		      "\u8f93\u5165\u4e2a\u6570", null, JOptionPane.ERROR_MESSAGE);				
			return;
		}
		int count = 0;
		if(countString != null){
			try {
				count = Integer.parseInt(countString); 
			} catch (Exception ei) {
				count = 0;
			}	
		}
		if(count == 0 || count > (SW_DATA_COUNT - 1)) {
		    JOptionPane.showMessageDialog(this,
		      "\u8f93\u5165\u4e2a\u6570", null, JOptionPane.ERROR_MESSAGE);				
			return;
		}
		for(int index = 0; index < count; index++){
			String str = swData[index].getText();

			
			if(str == null) {
			    JOptionPane.showMessageDialog(this,
			      "\u8f93\u5165\u6570\u636e", null, JOptionPane.ERROR_MESSAGE);				
				return;
			}
			int value = -1;
			try {
				value = Integer.parseInt(str); 
			} catch (Exception ei) {
				value = -1;
			}	

			
			if(value == -1) {
			    JOptionPane.showMessageDialog(this,
			      "\u8f93\u5165\u6570\u636e", null, JOptionPane.ERROR_MESSAGE);				
				return;
			}		

			dataString = dataString + CMD_SPLIT + getValidString(str);
			

		}
	 doom */
		
		String cmdStr = getValidString(addressString);// + CMD_SPLIT + getValidString(countString) + dataString;
		/*
		if(swRecordStr == null)
			swRecordStr = "";
		else
			swRecordStr = swRecord.getText();
		swRecordStr = swRecordStr + cmdStr + LINE_SEPATATOR;
		if(swRecord != null){
			swRecord.setText(swRecordStr);
		}
		*/
	/* doom 
		//System.out.println("===========os.name:"+System.getProperties().getProperty("os.name"));
		//System.out.println("===========file.separator:"+System.getProperties().getProperty("file.separator"));	
	 doom */
		String cmdString = null;
		setADBPath();
		cmdString = ADB_PATH+" shell echo " + cmdStr + " > " + CMD_FILE_RECV;
		
		//cmdString =  ADB_PATH+" shell echo \"10_02_FF_A2\"";
				
		//System.out.println("SingleWriteHandler cmdString:"+cmdString);
		//cmdString = ADB_PATH+" shell ls /system";
		//cmdString = ADB_PATH+" shell ls -l " + CMD_FILE;
		//cmdString = ADB_PATH+" shell echo " + CMD_FILE;

		//System.out.println("SingleWriteHandler cmdString:"+cmdString);
		try {
	               Process process = Runtime.getRuntime().exec(cmdString);  
	               final BufferedWriter outputStream = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
	               final BufferedReader inputStream = new BufferedReader(new InputStreamReader(process.getInputStream()));
	              final  BufferedReader  errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
	               new Thread(new Runnable() {
	                   String line;
	                    public void run() {
	                       //System.out.println("SingleWriteHandler listener started");
				   String line_separator = System.getProperty("line.separator");
	                       //System.out.println("SingleWriteHandler run line_separator:"+line_separator);

						   
						   String resultStr = "";
	                        try {
					int count = 0;
	                            while((line=inputStream.readLine()) != null) {
	                               //System.out.println(line);
					   resultStr = line;
					   break;
	                           }
					//  10_02_ff_a2
					//updateSingleReadInfo(resultStr);
					/* 
				      if(swResult != null){
						swResult.setText(resultStr);
				      	}
				      	*/
	                        } catch (IOException e) {
	                           //e.printStackTrace();  
	                        }

	                    }
	               }).start();
	               new Thread(new Runnable() {
	                    final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	                    public void run() {
	                       //System.out.println("SingleWriteHandler writer started");
	                        String line;
	                        try {
	                            while ((line =br.readLine()) != null) {
	                               outputStream.write(line + LINE_SEPATATOR);
	                               outputStream.flush();
	                            }
	                        } catch (IOException e) {
	                           //e.printStackTrace();  
	                        }
	                    }
	               }).start();
	               int i = process.waitFor();
	               //System.out.println("SingleWriteHandler i=" + i);
	           } catch (Exception e) {
	               e.printStackTrace();
	           }
	    }

	   private boolean checkBatchDataValid(String[] batchList, boolean write){
	   	boolean valid = true;
		//System.out.println("checkBatchDataValid write:"+write);
		if(write){
			for(int index = 0; index < batchList.length; index++){
				//System.out.println("checkBatchDataValid batchList["+index+"]:"+batchList[index]);

			}
		}else{
			for(int index = 0; index < batchList.length; index++){
				//System.out.println("checkBatchDataValid batchList["+index+"]:"+batchList[index]);

			}		
		}
		return valid;
	   }
	   private void BatchWriteHandlerEn(boolean shift, int rowIndex){
	   //System.out.println("BatchWriteHandler");
	   //if(swBatchArea != null)
	   	{
		   //String batchText = swBatchArea.getText();
		   //if(batchText != null)
		   	{
			   setADBPath();
			   ////System.out.println("BatchWriteHandler batchText:"+batchText);
			   //String[] batchTextList = batchText.split(LINE_SEPATATOR);
			   String[] batchTextList = null;
			   if(!shift){
			   	batchTextList = getBatchWriteListText();
			   }else{
			   	String lineStr2 = getBatchWriteLineText2(rowIndex);
				String[] dataListStr = new String[1];
				dataListStr[0] = lineStr2;
				batchTextList = dataListStr;
			   }
			   //System.out.println("BatchWriteHandler LINE_SEPATATOR:"+LINE_SEPATATOR);
			   if(batchTextList != null && batchTextList.length > 0){			   
				   //System.out.println("BatchWriteHandler batchTextList.length:"+batchTextList.length);
				   if(checkBatchDataValid(batchTextList, true)){
					   
					   String cmdStringList = "";//*"#!/bin/bash" + */LINE_SEPATATOR;
					   String osStr = System.getProperties().getProperty("os.name");				   
					   if(osStr != null && "Linux".equals(osStr)){
						   CMD_PATH = CMD_PATH_LINUX;
					   }else{
						   CMD_PATH = CMD_PATH_WINDOWS;
					   }
					   
					   for(int index = 0; index < batchTextList.length; index++){
						   //if(osStr != null && "Linux".equals(osStr)){
						   //	   cmdStringList += ADB_PATH+" shell echo " + batchTextList[index] + " > " + CMD_FILE;
						   //}else{
							   cmdStringList += ADB_PATH+" shell \"echo " + batchTextList[index] + " > " + CMD_FILE + "\"";
						   //}
						   if(index != (batchTextList.length - 1))
							   cmdStringList += LINE_SEPATATOR;
					   }
					   //System.out.println("BatchWriteHandler cmdStringList:"+cmdStringList);
					   boolean writeSuccessfully = false;
					   try{
	   
						   File file =new File(CMD_PATH);
						   if(!file.exists()){
							   file.createNewFile();
						   }
						   
						   FileWriter fileWritter = new FileWriter(CMD_PATH);
						   BufferedWriter bufferWritter = new BufferedWriter(fileWritter);
						   bufferWritter.write(cmdStringList);
						   bufferWritter.close();
						   //System.out.println("BatchWriteHandler write "+CMD_PATH+": successfully");
						   writeSuccessfully = true;
					   }catch(IOException e){
						   //System.out.println("BatchWriteHandler write "+CMD_PATH+": failed "+e.toString());
						   e.printStackTrace();
					   }   
					   if(writeSuccessfully){

						   try {
								String cmdStr = null;
							   if(osStr != null && "Linux".equals(osStr)){
									Runtime.getRuntime().exec("chmod 777 "+CMD_PATH);  
								   cmdStr = "bash " + CMD_PATH;
							   }else{
								   cmdStr = CMD_PATH;
							   }
							   swError.setText("");
							   swResult.setText("");
									  Process process = Runtime.getRuntime().exec(cmdStr);	
	/* jdj-tieto-2014-12-3 21:44:59 
									  final BufferedWriter batchOutputStream = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
	 jdj-tieto-2014-12-3 21:44:59 */
									  final BufferedReader batchInputStream = new BufferedReader(new InputStreamReader(process.getInputStream()));
									 final	BufferedReader	batchErrorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
									  new Thread(new Runnable() {
										   String line;
										   public void run() {
											  //System.out.println("BatchWriteHandler listener batchErrorReader started");
	   
									  String resultStr = "";
											   try {
												   while((line=batchErrorReader.readLine()) != null) {
													  //System.out.println(line);
													  line = line.replace(CMD_FILE, "write file");					  
													  line = line.replace(CMD_PATH, "script");
													  
													 resultStr = resultStr + line + LINE_SEPATATOR; 				   
												  }
									   //System.out.println("BatchWriteHandler batchErrorReader  resultStr:"+resultStr);
										 if(swError != null && (resultStr != null && !resultStr.equals(""))){
										   swError.setText(resultStr);
										   }
											   } catch (IOException e) {
												  //e.printStackTrace();  
											   }
	   
										   }
									  }).start();								 
									  new Thread(new Runnable() {
										   String line;
										   public void run() {
											  //System.out.println("BatchWriteHandler listener batchInputStream started");
	   
									  String resultStr = "";
											   try {
												   while((line=batchInputStream.readLine()) != null) {
													  //System.out.println(line);
													  line = line.replace(CMD_FILE, "write file");					  
													  line = line.replace(CMD_PATH, "script");
													 resultStr = resultStr + line + LINE_SEPATATOR; 				   
												  }
									   //System.out.println("BatchWriteHandler batchInputStream resultStr:"+resultStr);
										 if(swResult != null && (resultStr != null && !resultStr.equals(""))){
										   swResult.setText(resultStr);
										   }
											   } catch (IOException e) {
												  //e.printStackTrace();  
											   }
	   
										   }
									  }).start();
	/* jdj-tieto-2014-12-3 21:44:54 
									  new Thread(new Runnable() {
										   final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
										   public void run() {
											  //System.out.println("BatchWriteHandler writer started");
											   String line;
											   try {
												   while ((line =br.readLine()) != null) {
													  batchOutputStream.write(line + LINE_SEPATATOR);
													  batchOutputStream.flush();
												   }
											   } catch (IOException e) {
												  //e.printStackTrace();  
											   }
										   }
									  }).start();				   
	 jdj-tieto-2014-12-3 21:44:54 */
									  int i = process.waitFor();

									TimeDialog d = new TimeDialog();  
									int result = d.showDialog(this, "\u53d1\u9001\u6210\u529f\uff01", 1);

									  //System.out.println("BatchWriteHandler i=" + i);
								  } catch (Exception e) {
									  e.printStackTrace();
								  } 	
					   }
				   }
			   }
		   }
	   }
	   }
	   private void BatchReadHandlerEn(){
	   //System.out.println("BatchReadHandler");
	   //if(swBatchArea != null)
	   	{
		   //String batchText = swBatchArea.getText();
		   //if(batchText != null)
		   	{
			   ////System.out.println("BatchReadHandler batchText:"+batchText);
			   setADBPath();
			   //String[] batchTextList = batchText.split(LINE_SEPATATOR);
			   String[] batchTextList = getBatchReadListText();
			   if(batchTextList != null && batchTextList.length > 0){
				   
				   if(checkBatchDataValid(batchTextList, false/* read */)){
					   
					   String cmdStringList = "";///*"#!/bin/bash" + */LINE_SEPATATOR;
					   String osStr = System.getProperties().getProperty("os.name");
					   if(osStr != null && "Linux".equals(osStr)){
						   CMD_PATH = CMD_PATH_LINUX;
					   }else{
						   CMD_PATH = CMD_PATH_WINDOWS;
					   }
					   
					   for(int index = 0; index < batchTextList.length; index++){
						   //if(osStr != null && "Linux".equals(osStr)){
						   //cmdStringList += ADB_PATH+" shell echo " + batchTextList[index] + " > " + CMD_FILE_RECV;
						   //}else{
							   cmdStringList += ADB_PATH+" shell \"echo " + batchTextList[index] + " > " + CMD_FILE_RECV+"\"";
						   //}
						   if(index != (batchTextList.length - 1))
							   cmdStringList += LINE_SEPATATOR;
					   }
					   //System.out.println("BatchReadHandler cmdStringList:"+cmdStringList);
					   boolean writeSuccessfully = false;
					   try{
	   
						   File file =new File(CMD_PATH);
						   if(!file.exists()){
							   file.createNewFile();
						   }
						   
						   FileWriter fileWritter = new FileWriter(CMD_PATH);
						   BufferedWriter bufferWritter = new BufferedWriter(fileWritter);
						   bufferWritter.write(cmdStringList);
						   bufferWritter.close();
						   //System.out.println("BatchReadHandler write "+CMD_PATH+": successfully");
						   writeSuccessfully = true;
					   }catch(IOException e){
						   //System.out.println("BatchReadHandler write "+CMD_PATH+": failed "+e.toString());
						   e.printStackTrace();
					   }   
					   if(writeSuccessfully){
						   /*
						   if(swRecordStr == null)
							   swRecordStr = "";
						   else
							   swRecordStr = swRecord.getText();
						   */
						   /*
						   swRecordStr = batchText;
						   if(swRecord != null){
							   swRecord.setText(swRecordStr);
						   }
						   */
						   try {
								String cmdStr = null;
							   if(osStr != null && "Linux".equals(osStr)){
									Runtime.getRuntime().exec("chmod 777 "+CMD_PATH);  
								   cmdStr = "bash " + CMD_PATH;
							   }else{
								   cmdStr = CMD_PATH;
							   }
							   swError.setText("");
							   swResult.setText("");
									  Process process = Runtime.getRuntime().exec(cmdStr);	
	/* jdj-tieto-2014-12-3 21:45:2 
									  final BufferedWriter batchOutputStream = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
	 jdj-tieto-2014-12-3 21:45:2 */
									  final BufferedReader batchInputStream = new BufferedReader(new InputStreamReader(process.getInputStream()));
									 final	BufferedReader	batchErrorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
									  new Thread(new Runnable() {
										   String line;
										   public void run() {
											  //System.out.println("BatchReadHandler listener batchErrorReader started");
	   
									  String resultStr = "";
											   try {
												   while((line=batchErrorReader.readLine()) != null) {
													  //System.out.println(line);												  
													  line = line.replace(CMD_FILE_RECV, "write file");							  
													  line = line.replace(CMD_PATH, "script");
													 resultStr = resultStr + line + LINE_SEPATATOR; 				   
												  }
									   //System.out.println("BatchReadHandler batchErrorReader  resultStr:"+resultStr);
										 if(swError != null && (resultStr != null && !resultStr.equals(""))){
										   swError.setText(resultStr);
										   }
											   } catch (IOException e) {
												  //e.printStackTrace();  
											   }
	   
										   }
									  }).start();								 
									  new Thread(new Runnable() {
										   String line;
										   public void run() {
											  //System.out.println("BatchReadHandler listener batchInputStream started");
	   
									  String resultStr = "";
											   try {
												   while((line=batchInputStream.readLine()) != null) {
													  //System.out.println(line);						  
													  line = line.replace(CMD_FILE_RECV, "write file");						  
													  line = line.replace(CMD_PATH, "script");
													 resultStr = resultStr + line + LINE_SEPATATOR; 				   
												  }
									   //System.out.println("BatchReadHandler batchInputStream resultStr:"+resultStr);
										 if(swResult != null && (resultStr != null && !resultStr.equals(""))){
										   swResult.setText(resultStr);
										   }
											   } catch (IOException e) {
												  //e.printStackTrace();  
											   }
	   
										   }
									  }).start();
	/* jdj-tieto-2014-12-3 21:45:16 
									  new Thread(new Runnable() {
										   final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
										   public void run() {
											  //System.out.println("BatchReadHandler writer started");
											   String line;
											   try {
												   while ((line =br.readLine()) != null) {
													  batchOutputStream.write(line + LINE_SEPATATOR);
													  batchOutputStream.flush();
												   }
											   } catch (IOException e) {
												  //e.printStackTrace();  
											   }
										   }
									  }).start();
	 jdj-tieto-2014-12-3 21:45:16 */
									  int i = process.waitFor();

									TimeDialog d = new TimeDialog();  
									int result = d.showDialog(this, "\u8bfb\u53d6\u6210\u529f\uff01", 1);
	
									  //System.out.println("BatchReadHandler i=" + i);
								  } catch (Exception e) {
									  e.printStackTrace();
								  } 					   
					   }
				   }
			   }
		   }
	   }
	   }

	    private void BatchWriteHandler(){
		//System.out.println("BatchWriteHandler");
		if(swBatchArea != null){
			String batchText = swBatchArea.getText();
			if(batchText != null){
				setADBPath();
				//System.out.println("BatchWriteHandler batchText:"+batchText);
				String[] batchTextList = batchText.split(LINE_SEPATATOR);
				
				//System.out.println("BatchWriteHandler LINE_SEPATATOR:"+LINE_SEPATATOR);
				if(batchTextList != null && batchTextList.length > 0){				
					//System.out.println("BatchWriteHandler batchTextList.length:"+batchTextList.length);
					if(checkBatchDataValid(batchTextList, true)){
						
						String cmdStringList = "";//*"#!/bin/bash" + */LINE_SEPATATOR;
						String osStr = System.getProperties().getProperty("os.name");					
						if(osStr != null && "Linux".equals(osStr)){
							CMD_PATH = CMD_PATH_LINUX;
						}else{
							CMD_PATH = CMD_PATH_WINDOWS;
						}
						
						for(int index = 0; index < batchTextList.length; index++){
							if(osStr != null && "Linux".equals(osStr)){
								cmdStringList += ADB_PATH+" shell echo " + batchTextList[index] + " > " + CMD_FILE;
							}else{
								cmdStringList += ADB_PATH+" shell \"echo " + batchTextList[index] + " > " + CMD_FILE + "\"";
							}
							if(index != (batchTextList.length - 1))
								cmdStringList += LINE_SEPATATOR;
						}
						//System.out.println("BatchWriteHandler cmdStringList:"+cmdStringList);
						boolean writeSuccessfully = false;
						try{

							File file =new File(CMD_PATH);
							if(!file.exists()){
								file.createNewFile();
							}
							
							FileWriter fileWritter = new FileWriter(CMD_PATH);
							BufferedWriter bufferWritter = new BufferedWriter(fileWritter);
							bufferWritter.write(cmdStringList);
							bufferWritter.close();
							//System.out.println("BatchWriteHandler write "+CMD_PATH+": successfully");
							writeSuccessfully = true;
						}catch(IOException e){
							//System.out.println("BatchWriteHandler write "+CMD_PATH+": failed "+e.toString());
							e.printStackTrace();
						}	
						if(writeSuccessfully){
							/*
							if(swRecordStr == null)
								swRecordStr = "";
							else
								swRecordStr = swRecord.getText();
							*/
							/*
							swRecordStr = batchText;
							if(swRecord != null){
								swRecord.setText(swRecordStr);
							}
							*/
							try {
								 String cmdStr = null;
			 					if(osStr != null && "Linux".equals(osStr)){
									 Runtime.getRuntime().exec("chmod 777 "+CMD_PATH);  
									cmdStr = "bash " + CMD_PATH;
			 					}else{
									cmdStr = CMD_PATH;
			 					}
							   swError.setText("");
							   swResult.setText("");
						               Process process = Runtime.getRuntime().exec(cmdStr);  
	/* jdj-tieto-2014-12-3 21:45:27 
						               final BufferedWriter batchOutputStream = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
	 jdj-tieto-2014-12-3 21:45:27 */
						               final BufferedReader batchInputStream = new BufferedReader(new InputStreamReader(process.getInputStream()));
						              final  BufferedReader  batchErrorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
						               new Thread(new Runnable() {
						                    String line;
						                    public void run() {
						                       //System.out.println("BatchWriteHandler listener batchErrorReader started");

									   String resultStr = "";
						                        try {
						                            while((line=batchErrorReader.readLine()) != null) {
						                               //System.out.println(line);
									          resultStr = resultStr + line + LINE_SEPATATOR;			        
						                           }
										//System.out.println("BatchWriteHandler batchErrorReader  resultStr:"+resultStr);
									      if(swError != null && (resultStr != null && !resultStr.equals(""))){
											swError.setText(resultStr);
									      	}
						                        } catch (IOException e) {
						                           //e.printStackTrace();  
						                        }

						                    }
						               }).start();								  
						               new Thread(new Runnable() {
						                    String line;
						                    public void run() {
						                       //System.out.println("BatchWriteHandler listener batchInputStream started");

									   String resultStr = "";
						                        try {
						                            while((line=batchInputStream.readLine()) != null) {
						                               //System.out.println(line);
									          resultStr = resultStr + line + LINE_SEPATATOR;			        
						                           }
										//System.out.println("BatchWriteHandler batchInputStream resultStr:"+resultStr);
									      if(swResult != null && (resultStr != null && !resultStr.equals(""))){
											swResult.setText(resultStr);
									      	}
						                        } catch (IOException e) {
						                           //e.printStackTrace();  
						                        }

						                    }
						               }).start();
	/* jdj-tieto-2014-12-3 21:45:32 
						               new Thread(new Runnable() {
						                    final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
						                    public void run() {
						                       //System.out.println("BatchWriteHandler writer started");
						                        String line;
						                        try {
						                            while ((line =br.readLine()) != null) {
						                               batchOutputStream.write(line + LINE_SEPATATOR);
						                               batchOutputStream.flush();
						                            }
						                        } catch (IOException e) {
						                           //e.printStackTrace();  
						                        }
						                    }
						               }).start();
	 jdj-tieto-2014-12-3 21:45:32 */
						               int i = process.waitFor();
						               //System.out.println("BatchWriteHandler i=" + i);
						           } catch (Exception e) {
						               e.printStackTrace();
						           }						
						}
					}
				}
			}
		}
	    }
	    private void BatchReadHandler(){
		//System.out.println("BatchReadHandler");
		if(swBatchArea != null){
			String batchText = swBatchArea.getText();
			if(batchText != null){
				//System.out.println("BatchReadHandler batchText:"+batchText);
				setADBPath();
				String[] batchTextList = batchText.split(LINE_SEPATATOR);
				if(batchTextList != null && batchTextList.length > 0){
					
					if(checkBatchDataValid(batchTextList, false/* read */)){
						
						String cmdStringList = "";///*"#!/bin/bash" + */LINE_SEPATATOR;
						String osStr = System.getProperties().getProperty("os.name");
						if(osStr != null && "Linux".equals(osStr)){
							CMD_PATH = CMD_PATH_LINUX;
						}else{
							CMD_PATH = CMD_PATH_WINDOWS;
						}
						
						for(int index = 0; index < batchTextList.length; index++){
							if(osStr != null && "Linux".equals(osStr)){
							cmdStringList += ADB_PATH+" shell echo " + batchTextList[index] + " > " + CMD_FILE_RECV;
							}else{
								cmdStringList += ADB_PATH+" shell \"echo " + batchTextList[index] + " > " + CMD_FILE_RECV+"\"";
							}
							if(index != (batchTextList.length - 1))
								cmdStringList += LINE_SEPATATOR;
						}
						//System.out.println("BatchReadHandler cmdStringList:"+cmdStringList);
						boolean writeSuccessfully = false;
						try{

							File file =new File(CMD_PATH);
							if(!file.exists()){
								file.createNewFile();
							}
							
							FileWriter fileWritter = new FileWriter(CMD_PATH);
							BufferedWriter bufferWritter = new BufferedWriter(fileWritter);
							bufferWritter.write(cmdStringList);
							bufferWritter.close();
							//System.out.println("BatchReadHandler write "+CMD_PATH+": successfully");
							writeSuccessfully = true;
						}catch(IOException e){
							//System.out.println("BatchReadHandler write "+CMD_PATH+": failed "+e.toString());
							e.printStackTrace();
						}	
						if(writeSuccessfully){
							/*
							if(swRecordStr == null)
								swRecordStr = "";
							else
								swRecordStr = swRecord.getText();
							*/
							/*
							swRecordStr = batchText;
							if(swRecord != null){
								swRecord.setText(swRecordStr);
							}
							*/
							try {
								 String cmdStr = null;
			 					if(osStr != null && "Linux".equals(osStr)){
									 Runtime.getRuntime().exec("chmod 777 "+CMD_PATH);  
									cmdStr = "bash " + CMD_PATH;
			 					}else{
									cmdStr = CMD_PATH;
			 					}
							   swError.setText("");
							   swResult.setText("");
						               Process process = Runtime.getRuntime().exec(cmdStr);  
	/* jdj-tieto-2014-12-3 21:45:36 
						               final BufferedWriter batchOutputStream = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
	 jdj-tieto-2014-12-3 21:45:36 */
						               final BufferedReader batchInputStream = new BufferedReader(new InputStreamReader(process.getInputStream()));
						              final  BufferedReader  batchErrorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
						               new Thread(new Runnable() {
						                    String line;
						                    public void run() {
						                       //System.out.println("BatchReadHandler listener batchErrorReader started");

									   String resultStr = "";
						                        try {
						                            while((line=batchErrorReader.readLine()) != null) {
						                               //System.out.println(line);
									          resultStr = resultStr + line + LINE_SEPATATOR;			        
						                           }
										//System.out.println("BatchReadHandler batchErrorReader  resultStr:"+resultStr);
									      if(swError != null && (resultStr != null && !resultStr.equals(""))){
											swError.setText(resultStr);
									      	}
						                        } catch (IOException e) {
						                           //e.printStackTrace();  
						                        }

						                    }
						               }).start();								  
						               new Thread(new Runnable() {
						                    String line;
						                    public void run() {
						                       //System.out.println("BatchReadHandler listener batchInputStream started");

									   String resultStr = "";
						                        try {
						                            while((line=batchInputStream.readLine()) != null) {
						                               //System.out.println(line);
									          resultStr = resultStr + line + LINE_SEPATATOR;			        
						                           }
										//System.out.println("BatchReadHandler batchInputStream resultStr:"+resultStr);
									      if(swResult != null && (resultStr != null && !resultStr.equals(""))){
											swResult.setText(resultStr);
									      	}
						                        } catch (IOException e) {
						                           //e.printStackTrace();  
						                        }

						                    }
						               }).start();
	/* jdj-tieto-2014-12-3 21:45:40 
						               new Thread(new Runnable() {
						                    final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
						                    public void run() {
						                       //System.out.println("BatchReadHandler writer started");
						                        String line;
						                        try {
						                            while ((line =br.readLine()) != null) {
						                               batchOutputStream.write(line + LINE_SEPATATOR);
						                               batchOutputStream.flush();
						                            }
						                        } catch (IOException e) {
						                           //e.printStackTrace();  
						                        }
						                    }
						               }).start();
	 jdj-tieto-2014-12-3 21:45:40 */
						               int i = process.waitFor();
						               //System.out.println("BatchReadHandler i=" + i);
						           } catch (Exception e) {
						               e.printStackTrace();
						           }						
						}
					}
				}
			}
		}
	    }	

/* <-- wangmingdong -12-31-2014 23:11:33 */
	private void AddrTableWriteHandler(int selectedRow){
		BatchWriteHandlerEn(true, selectedRow);
/* <-- wangmingdong -1-1-2015 0:27:52 
		System.out.println("AddrTableWriteHandler selectedRow:"+selectedRow);	
		String lineStr = getBatchWriteLineText2(selectedRow);
		System.out.println("AddrTableWriteHandler lineStr:"+lineStr);	
		String cmdStr = " shell \"echo " + lineStr +  " > " + CMD_FILE + "\"";
		System.out.println("AddrTableWriteHandler cmdStr:"+cmdStr);	
		rcCMDHandler(cmdStr);
--> wangmingdong  */
	}
/* --> wangmingdong  */

	    private String[] ImportTextFilter(){
		String inputText = swRecord.getText();
		if(inputText != null){
			String[] inputList = inputText.split("\n");
			//System.out.println("ImportTextFilter inputList.length:"+inputList.length);
			if(inputList != null && inputList.length > 0){
/* <-- wangmingdong -1-11-2015 23:26:10 
				for(int rowIndex = 0; rowIndex < inputList.length; rowIndex++){
					//System.out.println("ImportTextFilter  inputList["+rowIndex+"]:"+inputList[rowIndex]);	
				}
--> wangmingdong  */
				return inputList;
			}
		}
		return null;
	    }

	private String getShiftAddrStr(String lineDataStr){
		// {0x39, 0x0, 0x1, {0xXX}},
		//System.out.println("getShiftAddrStr lineDataStr:"+lineDataStr);
		int startIndex = lineDataStr.indexOf(",{");
		int endIndex = lineDataStr.indexOf("}},");
		//System.out.println("getShiftAddrStr startIndex:"+startIndex);
		//System.out.println("getShiftAddrStr endIndex:"+endIndex);
		if((startIndex + 2) < endIndex){
			String shiftAddrStr = lineDataStr.substring(startIndex + 2, endIndex);
			//System.out.println("getShiftAddrStr shiftAddrStr:"+shiftAddrStr);
			shiftAddrStr = shiftAddrStr.replace("0x", "");
			//System.out.println("getShiftAddrStr shiftAddrStr:"+shiftAddrStr);
			return shiftAddrStr;
		}else{
			return null;
		}
	}

	    private void ImportHandler(boolean batch){
			//System.out.println("ImportHandler batch:"+batch);

			//ImportTextFilter();
			
			String inputText = swRecord.getText();
			//System.out.println("ImportHandler inputText:"+inputText);
			if(inputText != null)
			{
				String[] inputList = inputText.split("\n");
				//System.out.println("ImportHandler inputList.length:"+inputList.length);
				if(inputList != null && inputList.length > 0){
					
					boolean ioFormatDCS = ioFormatDCSSelected();
					boolean isShiftClosed = isShiftClosed();
					swAddrTable = null;
					swCreateAddrTable(inputList.length);

					int itemNum = 0, rowIndex = 0, listIndex = 0;
					String shiftAddrStr = null;
					for(itemNum = 0, rowIndex = 0, listIndex = 0; itemNum < inputList.length; itemNum++){
						
						inputList[itemNum] = inputList[itemNum].replaceAll("\\s*", "");  

						if(inputList[itemNum].equals(""))
							continue;

						listIndex++;
						//System.out.println("ioFormatDCS listIndex:"+listIndex);	
						if(!isShiftClosed && (listIndex%2 == 1)){
							if((shiftAddrStr = getShiftAddrStr(inputList[itemNum])) != null){
								continue;
							}else{
								ToastShow("\u7b2c"+(itemNum+1)+"\u884c\u6570\u636e\u6709\u8bef\uff01");
								return;
							}
						}
						
						inputList[itemNum] = inputList[itemNum] .substring(0, inputList[itemNum].indexOf("}},"));
						inputList[itemNum] = inputList[itemNum].replace("{", "");
						inputList[itemNum] = inputList[itemNum].replace("}},", "");
						//System.out.println("ImportHandler 1 inputList["+itemNum+"]:"+inputList[itemNum]);	

						if(ioFormatDCS && inputList[itemNum].length() > 5){
							String ioFormatStr = inputList[itemNum].substring(0, 5);
							//System.out.println("ioFormatDCS ioFormatStr:"+ioFormatStr);	
							if(ioFormatStr != null && ioFormatStr.equals("0x39,")){ 
								inputList[itemNum] = inputList[itemNum].substring(5);
							}else{
								//System.out.println("ioFormatDCS Check Error !!!");
								//continue;
							}
						}
/* iryun jdj-tieto-2015-1-12 20:1:45 
						else if(!ioFormatDCS && inputList[itemNum].length() > 5){
							String ioFormatStr = inputList[itemNum].substring(0, 5);
							//System.out.println("! ioFormatDCS ioFormatStr:"+ioFormatStr);	
							if(ioFormatStr != null && ioFormatStr.equals("0x29,")){ 
								inputList[itemNum] = inputList[itemNum].substring(5);
							}else{
								//System.out.println("! ioFormatDCS Check Error !!!");	
								//continue;
							}
						}
 iryun jdj-tieto-2015-1-12 20:1:45 */
						
						//System.out.println("ImportHandler 2 inputList["+itemNum+"]:"+inputList[itemNum]);	
						String[] dataList = inputList[itemNum].split(",");
						if(dataList != null && dataList.length >= 3){
							
							for(int index = 0; index < 2; index++){
								//System.out.println("ImportHandler dataList["+index+"]:"+dataList[index]); 
								if(index == 0){
									setValueAtNoFireInternal(swAddrTable, (Object)dataList[index], rowIndex, index + 1);
									if(!isShiftClosed){
										setValueAtNoFireInternal(swAddrTable, (Object)shiftAddrStr, rowIndex, index + 2);
									}
									swFireTableCellUpdated(swAddrTable, rowIndex, index + 1);
								}else if(index == 1){
									String countStr = "1";
									if(dataList[index].contains("0x")){
										countStr = dataList[index].replace("0x", "");
										try{
											countStr = Integer.valueOf(countStr,16).toString();
										}catch(NumberFormatException nfe){
											countStr = "1";
										}
									}else{
										countStr = dataList[index];
									}
									setValueAtNoFireInternal(swAddrTable, (Object)countStr/*(dataList[index].replace("0x", ""))*/, rowIndex, swAddrColumnNames.length - 1 - 2/*rightShiftCount*/);								
									//System.out.println("ImportHandler dataList[index]:"+dataList[index]);
									int dataStrX = dataList[0].length() + dataList[1].length() + 2;
									String dataStr = inputList[itemNum].substring(dataStrX);
									//System.out.println("ImportHandler dataStr:"+dataStr);
									setValueAtNoFireInternal(swAddrTable, (Object)dataStr, rowIndex, swAddrColumnNames.length - 2 - 2/*rightShiftCount*/);
									swFireTableCellUpdated(swAddrTable, rowIndex, swAddrColumnNames.length - 1 - 2/*rightShiftCount*/);
									swPane.repaint();	
								}
							}
							rowIndex++;
						}
					}
					//System.out.println("ImportHandler rowIndex:"+rowIndex);
					//System.out.println("ImportHandler itemNum:"+itemNum);
					if(itemNum > rowIndex){
						for(int delIndex = itemNum - 1; delIndex >= rowIndex; delIndex--){
							((DefaultTableModel)swAddrTable.getModel()).removeRow(delIndex);
						}				
					}
				}
			}
	    }

		private String LineExport(boolean ioFormatDCS, boolean isShiftClosed, int rowItem){
			
/* iryun jdj-tieto-2015-1-12 20:1:54 
			String headerStr = "{0x29,";
 iryun jdj-tieto-2015-1-12 20:1:54 */
			String headerStr = "{";
			if(ioFormatDCS){
				headerStr = "{0x39,";
			}
			String dataStr = headerStr;
				
			int rowCount = -1;//swDataTable.getRowCount();//Integer.toHexString(rowCount)
			String addrStr = "";
			String countStr = "";
			String dataListStr = "";
			addrStr = (String)swAddrTable.getValueAt(rowItem, 1);
			countStr = (String)swAddrTable.getValueAt(rowItem, swAddrColumnNames.length - 1 - 2/*rightShiftCount*/);
			dataListStr = (String)swAddrTable.getValueAt(rowItem, swAddrColumnNames.length - 2 - 2/*rightShiftCount*/);
			if(dataListStr.length() == 1){
				dataListStr = "0" + dataListStr;
			}			
			if(!dataListStr.contains("0x")){
				dataListStr = "0x" + dataListStr;
			}
			
			try{
				rowCount = Integer.parseInt(countStr);
				//System.out.println("LineExport rowCount:"+rowCount);
			}catch(NumberFormatException nfe){
				rowCount = -1;
			}
			if(rowCount == -1){
				return null;
			}
			if(addrStr.length() == 1){
				addrStr = "0" + addrStr;
			}			
			dataStr += "0x" + addrStr + ",";
			String dataHexStr = Integer.toHexString(rowCount);
			if(dataHexStr.length() == 1){
				dataHexStr = "0" + dataHexStr;
			}
			dataHexStr = dataHexStr.toUpperCase();
			dataStr += "0x" + dataHexStr + ",{";
			dataStr += dataListStr + "}},";

			if(!isShiftClosed){ // {0x39, 0x0, 0x1, {0xXX}},
				String shiftDataStr = headerStr + "0x00,0x01,{";
				String shiftaddrStr = (String)swAddrTable.getValueAt(rowItem, 2);
				if(shiftaddrStr.length() == 1){
					shiftaddrStr = "0" + shiftaddrStr;
				}		
				shiftaddrStr = "0x" + shiftaddrStr;
				shiftDataStr = shiftDataStr + shiftaddrStr + "}},\n";				
				dataStr = shiftDataStr + dataStr;
			}
			
			return dataStr;
		}
		
	    private void ExportHandler(boolean batch){
			//System.out.println("ExportHandler batch:"+batch);
			if(!batch){

				int allCount = swAddrTable.getRowCount();
				int count = swAddrTable.getSelectedRowCount();
				if(allCount > 0 && count > 0){
					int[] list = swAddrTable.getSelectedRows();
					if(list != null && list.length > 0){
						boolean ioFormatDCS = ioFormatDCSSelected();
						boolean isShiftClosed = isShiftClosed();
						String dataStr = null;
						String dataListStr = "";
						for(int index = 0; index < list.length; index++){
							dataStr = LineExport(ioFormatDCS, isShiftClosed, list[index]);
							if(dataStr != null){
								dataListStr += dataStr + "\n";
							}	
						}
						swRecord.setText(dataListStr);
					}
				}
			}
	    }

		private String getBatchWriteLineText2(int rowItem){

			String dcsStr = "29";
			if(ioFormatDCSSelected()){
				dcsStr = "39";
			}
			String addrStr = (String)swAddrTable.getValueAt(rowItem, 2);
			String shiftStr = dcsStr+"_00_1_" + addrStr;
			String lineStr = dcsStr + "_"+getBatchWriteLineText(rowItem);
			//System.out.println("getBatchWriteLineText2 shiftStr:"+shiftStr);	
			//System.out.println("getBatchWriteLineText2 lineStr:"+lineStr);	

			return shiftStr + "_" + lineStr;
		}

		private String getBatchWriteLineText(int rowItem){
			
			String dataStr = "";
			int rowCount = -1;//swDataTable.getRowCount();//Integer.toHexString(rowCount)
			String addrStr = "";
			String countStr = "";
			String dataListStr = "";
			addrStr = (String)swAddrTable.getValueAt(rowItem, 1);
			countStr = (String)swAddrTable.getValueAt(rowItem, swAddrColumnNames.length - 1 - 2/*rightShiftCount*/);
			dataListStr = (String)swAddrTable.getValueAt(rowItem, swAddrColumnNames.length - 2 - 2/*rightShiftCount*/);
			//System.out.println("@@@ getBatchWriteLineText dataListStr:"+dataListStr);
			String[] dataList  = dataListStr.split(",");
			dataListStr = "";
			boolean hex = true;
			if(hex){
				for(int index = 0; index < dataList.length; index++){
					dataList[index] = dataList[index].replace("0x", "");
					if(index < (dataList.length - 1))
					dataListStr += dataList[index] + "_";
					else
					dataListStr += dataList[index];
				}
			}else
			{
				for(int index = 0; index < dataList.length; index++){
					dataList[index] = dataList[index].replace("0x", "");
					if(index < (dataList.length - 1))
					dataListStr += dataList[index] + "_";
					else
					dataListStr += dataList[index];
				}

			}
			//System.out.println("@@@ getBatchWriteLineText dataListStr:"+dataListStr);
			if(addrStr.length() == 1){
				addrStr = "0" + addrStr;
			}	
			if(hex){
				try{
					rowCount = Integer.parseInt(countStr);
					//System.out.println("getBatchWriteLineText rowCount:"+rowCount);
				}catch(NumberFormatException nfe){
					rowCount = -1;
				}
				if(rowCount == -1){
					return null;
				}
			
				dataStr += /*"0x" + */addrStr + "_";
				String dataHexStr = Integer.toHexString(rowCount);
				if(dataHexStr.length() == 1){
					dataHexStr = "0" + dataHexStr;
				}					
				dataHexStr = dataHexStr.toUpperCase();
				dataStr += /*"0x" + */dataHexStr + "_";
				dataStr += dataListStr;
			}
			else{
				if(countStr.length() == 1){
					countStr = "0" + countStr;
				}	
			
				dataStr += addrStr + "_";
				dataStr += countStr + "_";
				dataStr += dataListStr;
			}
			//System.out.println("getBatchWriteLineText dataStr:"+dataStr);
			return dataStr;
		}

		private String[] getBatchWriteListText(){

			int allCount = swAddrTable.getRowCount();
			int count = swAddrTable.getSelectedRowCount();
			if(allCount > 0 && count > 0){
				int[] list = swAddrTable.getSelectedRows();
				if(list != null && list.length > 0){				
					String dataStr = null;
					String[] dataListStr = new String[list.length];
					for(int index = 0; index < list.length; index++){
						dataStr = getBatchWriteLineText(list[index]);
						dataListStr[index] = dataStr;
					}
					return dataListStr;

				}
			}

			return null;
		}

		private String[] getBatchReadListText(){

			int allCount = swAddrTable.getRowCount();
			int count = swAddrTable.getSelectedRowCount();
			if(allCount > 0 && count > 0){
				int[] list = swAddrTable.getSelectedRows();
				if(list != null && list.length > 0){				
					String dataStr = null;
					String[] dataListStr = new String[list.length];
					for(int index = 0; index < list.length; index++){
						dataStr = (String)swAddrTable.getValueAt(list[index], 1);
						dataListStr[index] = dataStr;
					}
					return dataListStr;

				}
			}
			
			return null;

		}

	    private void AddrAddHandler(boolean batch, boolean prev){
			//System.out.println("AddrAddHandler batch:"+batch);
			int allCount = swAddrTable.getRowCount();
			//System.out.println("AddrAddHandler allCount:"+allCount);

	/* -2014-12-3 20:13:33 */
			if(allCount >= swAddrTableRowCountMax){			
				return;
			}
	/* -2014-12-3 20:13:33 */
			
			int count = swAddrTable.getSelectedRowCount();
			//System.out.println("AddrAddHandler count:"+count);
			int lastRow = -1;
			if(count == 1){
				int row = swAddrTable.getSelectedRow();
				//System.out.println("AddrAddHandler row:"+row);
				if(prev){
					lastRow = row;
				}else{
					lastRow = row + 1;					
				}
				//System.out.println("AddrAddHandler lastRow:"+lastRow);
			}
			else{
	/* jdj-tieto-2014-11-26 15:23:43 
				int[] list = swAddrTable.getSelectedRows();
				if(list != null && list.length > 0){
					for(int index = 0; index < list.length; index++){
						//System.out.println("AddrAddHandler list["+index+"]:"+list[index]);
						if(index == (list.length - 1)){
							lastRow = list[index];
						}
					}
				}
	 jdj-tieto-2014-11-26 15:23:43 */
			}
			if(allCount == 0
				|| (allCount > 0 && count == 0)){
				lastRow = 0;
			}
			//System.out.println("AddrAddHandler lastRow:"+lastRow);
			if(lastRow >= 0){
				String[] data = new String[swAddrColumnNames.length];
				data[0] = "\u5730\u5740" + (lastRow + 1);
				for(int j = 1; j < swAddrColumnNames.length; j++){
					if(j == (swAddrColumnNames.length - 1)){
							data[j] = "\u2193";
						}else if(j == (swAddrColumnNames.length - 2)){
							data[j] = "\u2191";
						}else if(j == (swAddrColumnNames.length - 1 - 2/*rightShiftCount*/)){
						data[j] = "1";				
					}else if(j == (swAddrColumnNames.length - 2 - 2/*rightShiftCount*/)
					|| j == 1 || j == 2){
						data[j] = "00";				
					}else{
						data[j] = "0";				
					}
				}
				((DefaultTableModel)swAddrTable.getModel()).insertRow(lastRow, data);
				int rowCount = swAddrTable.getRowCount();
				for(int index = 0; index < rowCount; index++){
					setValueAtNoFireInternal(swAddrTable, (Object)("\u5730\u5740" + (index + 1)), index, 0);
				}
				setAddrTableRowSelection(lastRow);
				
				swCreateAddrTable(rowCount);// updateUI
			}
	    }

	    private void AddrDelHandler(boolean batch){
			//System.out.println("AddrDelHandler batch:"+batch);
			int rowCount = swAddrTable.getRowCount();
			//System.out.println("AddrDelHandler rowCount:"+rowCount);
			int count = swAddrTable.getSelectedRowCount();
			//System.out.println("AddrDelHandler count:"+count);
			if(rowCount == 0 || count == 0)
				return;
			int preRow = 0;

			if(count == 1){
				int row = swAddrTable.getSelectedRow();
				//System.out.println("AddrDelHandler row:"+row);
				((DefaultTableModel)swAddrTable.getModel()).removeRow(row);
				preRow = row - 1;
			}
			else{
				int[] list = swAddrTable.getSelectedRows();
				if(list != null && list.length > 0){
					for(int index = list.length - 1; index >= 0; index--){
						((DefaultTableModel)swAddrTable.getModel()).removeRow(list[index]);
						if(index == 0){
							preRow = list[index] - 1;
						}
					}
				}
			}
			rowCount = swAddrTable.getRowCount();
			if(rowCount > 0){
				//System.out.println("AddrDelHandler rowCount:"+rowCount);
				if(preRow < 0 || preRow > (rowCount - 1)){
					preRow = 0;
				}
				//System.out.println("AddrDelHandler preRow:"+preRow);
				for(int index = 0; index < rowCount; index++){
					setValueAtNoFireInternal(swAddrTable, (Object)("\u5730\u5740" + (index + 1)), index, 0);
				}
				setAddrTableRowSelection(preRow);	
			}
			
			swCreateAddrTable(rowCount);// updateUI

	    }	

	    private void setAddrTableRowSelection(int rowItem){
			swAddrTable.setRowSelectionInterval(rowItem, rowItem);

			String value = (String)swAddrTable.getValueAt(rowItem, swAddrColumnNames.length - 1 - 2/*rightShiftCount*/);
			//System.out.println("setAddrTableRowSelection swAddrTable Number value :"+value );	
			value = value.replace("0x", "");
			if(value != null){
				int number = 0;
				try{
					number = Integer.parseInt(value);
				}catch(NumberFormatException nfe){
					number = 0;
				}
				//System.out.println("setAddrTableRowSelection swAddrTable Number 1 number:"+number);	
				if(number > 0 && number <= swDataTableRowCountMax){
					//System.out.println("setAddrTableRowSelection swAddrTable Number 2 number:"+number);	
				}else{
					number = 1;
					setValueAtNoFire(swAddrTable, (Object)"1", rowItem, swAddrColumnNames.length - 1 - 2/*rightShiftCount*/);					
				}
				int rowCount = -1;
				if(swDataTable != null)
					swDataTable.getRowCount();
				if(rowCount != number)
				swCreateDataTable(number);
				refreashTableData(swDataTable);
			}				
	    }
	    private void setAddrTableRowSelections(int firstItem, int lastItem){
			swAddrTable.setRowSelectionInterval(firstItem, lastItem);		
	    }

/* mss-2015-7-2 0:15:0 */
	    private String normalStrToHexStr(String normal){
	        String retStr = "00_00";
		try{
			retStr = Integer.toHexString(Integer.parseInt(normal));
			if(retStr != null){
				if (retStr.length() == 1)
					retStr = "000" + retStr;
				else if (retStr.length() == 2)
					retStr = "00" + retStr;
				else if (retStr.length() == 3)
					retStr = "0" + retStr;
				else if (retStr.length() == 4) 
					System.out.println("normalStrToHexStr");						
				else
					return "00_00";
			}
		}catch(NumberFormatException nfe){
			return "00_00";
		}
		if (retStr != null && retStr.length() == 4){			
			return retStr.substring(0, 2) + "_" + retStr.substring(2, 4);
		}else
			return "00_00";
           }

	    private String strLengthRejust(String normal){
	        String retStr = "00";
		if (normal.length() == 1){
			retStr = "0" + normal;
			return retStr;
		}else if (normal.length() == 2){
			System.out.println("strLengthRejust");	
			return normal;
		}else
			return "00";
           }

	    private void swPorchButtonHandler(){
	        String porchStr = "";
		for(int index = 0; index < swPorchList.length; index++){	
			if(swPorchList[index] == null || swPorchList[index].getText() == null ||swPorchList[index].getText().equals("")){
				porchStr = null;
				break;
			}
			String valueStr = "";
			if(index == 0)
				valueStr = normalStrToHexStr(swPorchList[index].getText());
			else if(index == 1)
				valueStr = normalStrToHexStr(swPorchList[index].getText());	
			else
				valueStr = strLengthRejust(swPorchList[index].getText());
			System.out.println("swPorchButtonHandler valueStr:"+valueStr);	
			
			if(index == 0)
			porchStr = porchStr + valueStr;
			else if(index == 1)
			porchStr = porchStr + "_" +valueStr;
			else
			porchStr = porchStr + "_" +valueStr;
		}
		if(porchStr != null){
			porchStr = "aa_55_11_" + porchStr;
			System.out.println("swPorchButtonHandler porchStr:"+porchStr);	
			swPorchCmdHandler(porchStr);
		}
		else
		System.out.println("swPorchButtonHandler porchStr NULL");	
	    }

	   private void swPorchCmdHandler(String porchStr){
	   //System.out.println("BatchWriteHandler");
	   //if(swBatchArea != null)
	   	{
		   //String batchText = swBatchArea.getText();
		   //if(batchText != null)
		   	{
			   setADBPath();
			   ////System.out.println("BatchWriteHandler batchText:"+batchText);
			   //String[] batchTextList = batchText.split(LINE_SEPATATOR);
/* mss-2015-7-2 8:26:32 
			   String[] batchTextList = null;
			   if(!shift){
			   	batchTextList = getBatchWriteListText();
			   }else{
			   	String lineStr2 = getBatchWriteLineText2(rowIndex);
				String[] dataListStr = new String[1];
				dataListStr[0] = lineStr2;
				batchTextList = dataListStr;
			   }
 mss-2015-7-2 8:26:32 */
			   //System.out.println("BatchWriteHandler LINE_SEPATATOR:"+LINE_SEPATATOR);
			   //if(batchTextList != null && batchTextList.length > 0)
			   {			   
				   //System.out.println("BatchWriteHandler batchTextList.length:"+batchTextList.length);
				   //if(checkBatchDataValid(batchTextList, true))
				   {
					   
					   String cmdStringList = "";//*"#!/bin/bash" + */LINE_SEPATATOR;
					   String osStr = System.getProperties().getProperty("os.name");				   
					   if(osStr != null && "Linux".equals(osStr)){
						   CMD_PATH = CMD_PATH_LINUX;
					   }else{
						   CMD_PATH = CMD_PATH_WINDOWS;
					   }
					   cmdStringList += ADB_PATH+" shell \"echo " + porchStr + " > " + CMD_FILE_PORCH + "\"";
					   
/* mss-2015-7-2 8:27:37 
					   for(int index = 0; index < batchTextList.length; index++){
							   cmdStringList += ADB_PATH+" shell \"echo " + batchTextList[index] + " > " + CMD_FILE + "\"";
						   if(index != (batchTextList.length - 1))
							   cmdStringList += LINE_SEPATATOR;
					   }
 mss-2015-7-2 8:27:37 */
					   System.out.println("swPorchCmdHandler cmdStringList:"+cmdStringList);
					   boolean writeSuccessfully = false;
					   try{
	   
						   File file =new File(CMD_PATH);
						   if(!file.exists()){
							   file.createNewFile();
						   }
						   
						   FileWriter fileWritter = new FileWriter(CMD_PATH);
						   BufferedWriter bufferWritter = new BufferedWriter(fileWritter);
						   bufferWritter.write(cmdStringList);
						   bufferWritter.close();
						   //System.out.println("BatchWriteHandler write "+CMD_PATH+": successfully");
						   writeSuccessfully = true;
					   }catch(IOException e){
						   //System.out.println("BatchWriteHandler write "+CMD_PATH+": failed "+e.toString());
						   e.printStackTrace();
					   }   
					   if(writeSuccessfully){

						   try {
								String cmdStr = null;
							   if(osStr != null && "Linux".equals(osStr)){
									Runtime.getRuntime().exec("chmod 777 "+CMD_PATH);  
								   cmdStr = "bash " + CMD_PATH;
							   }else{
								   cmdStr = CMD_PATH;
							   }
							   swError.setText("");
							   swResult.setText("");
									  Process process = Runtime.getRuntime().exec(cmdStr);	
	/* jdj-tieto-2014-12-3 21:44:59 
									  final BufferedWriter batchOutputStream = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
	 jdj-tieto-2014-12-3 21:44:59 */
									  final BufferedReader batchInputStream = new BufferedReader(new InputStreamReader(process.getInputStream()));
									 final	BufferedReader	batchErrorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
									  new Thread(new Runnable() {
										   String line;
										   public void run() {
											  //System.out.println("BatchWriteHandler listener batchErrorReader started");
	   
									  String resultStr = "";
											   try {
												   while((line=batchErrorReader.readLine()) != null) {
													  //System.out.println(line);
													  line = line.replace(CMD_FILE, "write file");					  
													  line = line.replace(CMD_PATH, "script");
													  
													 resultStr = resultStr + line + LINE_SEPATATOR; 				   
												  }
									   //System.out.println("BatchWriteHandler batchErrorReader  resultStr:"+resultStr);
										 if(swError != null && (resultStr != null && !resultStr.equals(""))){
										   swError.setText(resultStr);
										   }
											   } catch (IOException e) {
												  //e.printStackTrace();  
											   }
	   
										   }
									  }).start();								 
									  new Thread(new Runnable() {
										   String line;
										   public void run() {
											  //System.out.println("BatchWriteHandler listener batchInputStream started");
	   
									  String resultStr = "";
											   try {
												   while((line=batchInputStream.readLine()) != null) {
													  //System.out.println(line);
													  line = line.replace(CMD_FILE, "write file");					  
													  line = line.replace(CMD_PATH, "script");
													 resultStr = resultStr + line + LINE_SEPATATOR; 				   
												  }
									   //System.out.println("BatchWriteHandler batchInputStream resultStr:"+resultStr);
										 if(swResult != null && (resultStr != null && !resultStr.equals(""))){
										   swResult.setText(resultStr);
										   }
											   } catch (IOException e) {
												  //e.printStackTrace();  
											   }
	   
										   }
									  }).start();
	/* jdj-tieto-2014-12-3 21:44:54 
									  new Thread(new Runnable() {
										   final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
										   public void run() {
											  //System.out.println("BatchWriteHandler writer started");
											   String line;
											   try {
												   while ((line =br.readLine()) != null) {
													  batchOutputStream.write(line + LINE_SEPATATOR);
													  batchOutputStream.flush();
												   }
											   } catch (IOException e) {
												  //e.printStackTrace();  
											   }
										   }
									  }).start();				   
	 jdj-tieto-2014-12-3 21:44:54 */
									  int i = process.waitFor();

									TimeDialog d = new TimeDialog();  
									int result = d.showDialog(this, "\u53d1\u9001LCM\u53c2\u6570\u8bbe\u7f6e\u8bf7\u6c42", 1);

									  //System.out.println("BatchWriteHandler i=" + i);
								  } catch (Exception e) {
									  e.printStackTrace();
								  } 	
					   }
				   }
			   }
		   }
	   }
	   }	    
/* mss-2015-7-2 0:15:0 */
		
	    private JPanel createTabContentSingleRead(){
		return null;
	    }
	/* doom 

	    private final int SR_DATA_COUNT = 5;
	    private JTextField srAddress;
	    private JTextField srCount;
	    private JTextField[] srData = new JTextField[SR_DATA_COUNT];
	    private JTextArea srRecord;
	    private JTextArea srResult;
	    private JButton srRead;
	    private JButton srToWrite;
	    private String srRecordStr = "";

	    private JPanel createTabContentSingleRead(){
	       JPanel panel = new JPanel(new GridBagLayout());
		panel.setBorder(BorderFactory.createTitledBorder(getTabName(TAB_SINGLE_READ))); 
		GridBagConstraints c = new GridBagConstraints();	
		c.fill = GridBagConstraints.BOTH;
		c.insets = new Insets(5, 5, 5, 5);
		c.weightx = 1.0;

	       JLabel label;
	       JButton button;
		JTextField edit;
		JTextArea mtext;

		label = new JLabel("\u5730\u5740");
		label.setHorizontalAlignment(JLabel.CENTER);
		c.gridwidth = 1;
		c.gridheight = 1;
		c.gridx = 0;
		c.gridy = 0;
	       panel.add(label, c);
		label = new JLabel("\u4e2a\u6570");
		label.setHorizontalAlignment(JLabel.CENTER);
		c.gridwidth = 1;
		c.gridheight = 1;
		c.gridx = 1;
		c.gridy = 0;
	       panel.add(label, c);
		label = new JLabel("\u6570\u636e");
		label.setHorizontalAlignment(JLabel.CENTER);
		c.gridwidth = 1;
		c.gridheight = 1;
		c.gridx = 2;
		c.gridy = 0;
	       panel.add(label, c);

		label = new JLabel("\u64cd\u4f5c");
		label.setHorizontalAlignment(JLabel.CENTER);
		c.gridwidth = 2;
		c.gridheight = 1;
		c.gridx = 3;
		c.gridy = 0;
	       panel.add(label, c);

		label = new JLabel("\u8bb0\u5f55");
		label.setHorizontalAlignment(JLabel.LEFT);
		c.gridwidth = 1;
		c.gridheight = 1;
		c.gridx = 0;
		c.gridy = 6;
	       panel.add(label, c);
		label = new JLabel("\u8f93\u51fa");
		label.setHorizontalAlignment(JLabel.LEFT);
		c.gridwidth = 1;
		c.gridheight = 1;
		c.gridx = 1;
		c.gridy = 6;
	       panel.add(label, c);

		edit = new JTextField("");
		edit.setDocument(new IntegerDocument());
		srAddress = edit;
		edit.setHorizontalAlignment(JTextField.CENTER);
		c.gridwidth = 1;
		c.gridheight = 1;
		c.gridx = 0;
		c.gridy = 1;
	       panel.add(edit, c);		
		
		edit = new JTextField("");
		edit.setDocument(new IntegerDocument());
		srCount = edit;
		edit.setHorizontalAlignment(JTextField.CENTER);
		c.gridwidth = 1;
		c.gridheight = 1;
		c.gridx = 1;
		c.gridy = 1;
	       panel.add(edit, c);	
		   
		edit = new JTextField("");
		edit.setEditable(false);
		edit.setDocument(new IntegerDocument());
		srData[0] = edit;
		edit.setHorizontalAlignment(JTextField.CENTER);
		c.gridwidth = 1;
		c.gridheight = 1;
		c.gridx =2;
		c.gridy = 1;
	       panel.add(edit, c);		
		edit = new JTextField("");
		edit.setEditable(false);
		edit.setDocument(new IntegerDocument());
		srData[1] = edit;
		edit.setHorizontalAlignment(JTextField.CENTER);
		c.gridwidth = 1;
		c.gridheight = 1;
		c.gridx =2;
		c.gridy = 2;
	       panel.add(edit, c);		
		edit = new JTextField("");
		edit.setEditable(false);
		edit.setDocument(new IntegerDocument());
		srData[2] = edit;
		edit.setHorizontalAlignment(JTextField.CENTER);
		c.gridwidth = 1;
		c.gridheight = 1;
		c.gridx =2;
		c.gridy = 3;
	       panel.add(edit, c);		
		edit = new JTextField("");
		edit.setEditable(false);
		edit.setDocument(new IntegerDocument());
		srData[3] = edit;
		edit.setHorizontalAlignment(JTextField.CENTER);
		c.gridwidth = 1;
		c.gridheight = 1;
		c.gridx =2;
		c.gridy = 4;
	       panel.add(edit, c);		
		edit = new JTextField("");
		edit.setEditable(false);
		edit.setDocument(new IntegerDocument());
		srData[4] = edit;
		edit.setHorizontalAlignment(JTextField.CENTER);
		c.gridwidth = 1;
		c.gridheight = 1;
		c.gridx =2;
		c.gridy = 5;
	       panel.add(edit, c);	

		button = new JButton("\u8bfb\u53d6");
		srRead = button;
		button.addActionListener(this);
		c.gridwidth = 2;
		c.gridheight = 1;
		c.gridx = 3;
		c.gridy = 1;
	       panel.add(button, c);

		button = new JButton("\u8f6c\u81f3\u8f93\u5165");
		srToWrite = button;
		button.addActionListener(this);
		c.gridwidth = 2;
		c.gridheight = 1;
		c.gridx = 3;
		c.gridy = 5;
	       panel.add(button, c);

		c.weighty = 0.5;
		mtext = new JTextArea("\u7a7a\u767d");
		JScrollPane mTextScroll = new JScrollPane(mtext);
		srRecord= mtext;
		c.gridwidth = 1;
		c.gridheight = 2;
		c.gridx = 0;
		c.gridy = 7;
	       panel.add(mTextScroll, c);	
		mtext = new JTextArea("\u7a7a\u767d");
		mTextScroll = new JScrollPane(mtext);
		srResult = mtext;
		c.gridwidth = 4;
		c.gridheight = 2;
		c.gridx = 1;
		c.gridy = 7;
	       panel.add(mTextScroll, c);	
		   
	       return panel;
	    }
	 doom */

	/* doom 
	    private void SingleReadHandler(){

		String addressString = srAddress.getText();
		if(!isInteger(addressString)) {
		    JOptionPane.showMessageDialog(this,
		      "\u8f93\u5165\u5730\u5740", null, JOptionPane.ERROR_MESSAGE);				
			return;
		}

		String countString =  srCount.getText() ;
		if(!isInteger(countString))  {
		    JOptionPane.showMessageDialog(this,
		      "\u8f93\u5165\u4e2a\u6570", null, JOptionPane.ERROR_MESSAGE);				
			return;
		}
		int count = 0;
		if(countString != null){
			try {
				count = Integer.parseInt(countString); 
			} catch (Exception ei) {
				count = 0;
			}	
		}
		if(count == 0 || count > (SR_DATA_COUNT-1)) {
		    JOptionPane.showMessageDialog(this,
		      "\u8f93\u5165\u4e2a\u6570", null, JOptionPane.ERROR_MESSAGE);				
			return;
		}
		String cmdStr = getValidString(addressString) + CMD_SPLIT + getValidString(countString);


		srRecordStr = srRecordStr + cmdStr + "\r\n";
		if(srRecord != null){
			srRecord.setText(srRecordStr);
		}

		for(int index = 0; index < SR_DATA_COUNT; index++){
			srData[index].setText(""+index);
		}		
			
		String cmdString = ADB_PATH+" shell echo " + cmdStr + " > " + CMD_FILE_RECV;
		//System.out.println("SingleReadHandler cmdString:"+cmdString);
		//cmdString = ADB_PATH+" shell ls /system";
		//cmdString = ADB_PATH+" shell ls -l " + CMD_FILE_RECV;
		//cmdString = ADB_PATH+" shell echo " + CMD_FILE_RECV;

		//System.out.println("SingleReadHandler cmdString:"+cmdString);
		try {
	               Process process = Runtime.getRuntime().exec(cmdString);  
	               final BufferedWriter outputStream = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
	               final BufferedReader inputStream = new BufferedReader(new InputStreamReader(process.getInputStream()));
	              final  BufferedReader  errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
	               new Thread(new Runnable() {
	                   String line;
	                    public void run() {
	                       //System.out.println("SingleReadHandler listener started");
						   String line_separator = System.getProperty("line.separator");
	                       //System.out.println("SingleReadHandler run line_separator:"+line_separator);					   
				  		   String resultStr = "";
	                        try {
	                            while((line=inputStream.readLine()) != null) {
	                               //System.out.println(line);
				          resultStr = resultStr + line + line_separator;			        
	                           }
				      if(srResult != null){
						srResult.setText(resultStr);
				      	}
	                        } catch (IOException e) {
	                           //e.printStackTrace();  
	                        }

	                    }
	               }).start();
	               new Thread(new Runnable() {
	                    final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	                    public void run() {
	                       //System.out.println("SingleReadHandler writer started");
	                        String line;
	                        try {
	                            while ((line =br.readLine()) != null) {
	                               outputStream.write(line + "\r\n");
	                               outputStream.flush();
	                            }
	                        } catch (IOException e) {
	                           //e.printStackTrace();  
	                        }
	                    }
	               }).start();
	               int i = process.waitFor();
	               //System.out.println("SingleReadHandler i=" + i);
	           } catch (Exception e) {
	               e.printStackTrace();
	           }
	    }
	 doom */
		
	    private JPanel createTabContentMultiWrite(){
	       JPanel panel = new JPanel(new GridLayout(1,1));
	       JLabel label = new JLabel(getTabName(TAB_MULTI_WRITE));
	       label.setHorizontalAlignment(JLabel.CENTER);
	       panel.add(label);
	       return panel;
	    }
	    private JPanel createTabContentMultiRead(){
	       JPanel panel = new JPanel(new GridLayout(1,1));
	       JLabel label = new JLabel(getTabName(TAB_MULTI_READ));
	       label.setHorizontalAlignment(JLabel.CENTER);
	       panel.add(label);
	       return panel;
	    }
	/* -2014-11-10 15:34:36 */

	    private final static String SDCARD_ROOT = "/mnt/sdcard/";

	    private JPanel plPanel = null;
	    private JButton plLoadBtn = null;
	    private JButton plPushBtn = null;
	    private DefaultMutableTreeNode root = null;
	    private JTree fileTree = null;
	    private JScrollPane treeScroll = null;	
	    private JTree fileTreeDevice = null;
	    private DefaultMutableTreeNode fileTreeDeviceTopNode = null;
	    private JScrollPane treeScrollDevice = null;		
	    private DefaultMutableTreeNode currTreeNode = null;
	    private JButton plDeviceLoad = null;
	    private JButton plDevicePull = null;
	    private JButton plDeviceDel = null;
	    private FolderNode plFolderNode = null;
	    private JPopupMenu plPopupMenu = null;
	    private JMenuItem plMenuitemMkdir = null;
/* irb 2015-3-9 20:9:59 */
	    private JProgressBar plJProgressBar = null;
	    private JDialog plJDialog = null;
	    private String cmdStringList ;
/* irb 2015-3-9 20:9:59 */
	    public void layoutPushImageChilds(int width, int height){
			int padding = 10;

			int contentWidth = width - padding * 2;
			int contentHeight = height - padding * 2;

			int w = 0;
			int h = 0;
			w = (contentWidth -padding ) / 2;
			h = (contentHeight -padding ) * 4 / 5;
			
			treeScroll.setBounds(new Rectangle(padding, padding, w, h));
			treeScrollDevice.setBounds(new Rectangle(padding * 2 + w, padding, w, h));

			h = (contentHeight -padding ) * 1 / 5;
			w = w / 2;
			plLoadBtn.setBounds(new Rectangle(padding, padding * 2 + 4 * h, w- 5, h));		
			plPushBtn.setBounds(new Rectangle(padding + w + 5, padding * 2 + 4 * h, w- 5, h));

			w = w * 2;
			int startX = padding * 2 + w;
			w = w / 3;

			plDeviceLoad.setBounds(new Rectangle(startX, padding * 2 + 4 * h, w- 5, h));
			
			plDevicePull.setBounds(new Rectangle(startX + w + 5, padding * 2 + 4 * h, w- 10, h));
			
			plDeviceDel.setBounds(new Rectangle(startX + w * 2 + 5, padding * 2 + 4 * h, w- 5, h));
			
	    }

	class FileSystemModel implements TreeModel {
	 
	    I_fileSystem theRoot;
	 
	 
	    char fileType = I_fileSystem.ALL;//DIRECTORY;
	  
	 
	    public FileSystemModel(I_fileSystem fs) {
	 
	        theRoot = fs;
	 
	    }
	 
	 
	    public Object getRoot() {
	        return theRoot;
	    }
	 
	 
	    public Object getChild(Object parent, int index) {
	        return ((I_fileSystem) parent).getChild(fileType, index);
	    }
	 
	  
	    public int getChildCount(Object parent) {
	        return ((I_fileSystem) parent).getChildCount(fileType);
	    }
	 
	  
	 
	    public boolean isLeaf(Object node) {
	        return ((I_fileSystem) node).isLeaf(fileType);
	    }
	 
	  
	 
	    public int getIndexOfChild(Object parent, Object child) {
	        return ((I_fileSystem) parent).getIndexOfChild(fileType, child);
	    }
	 
	    public void valueForPathChanged(TreePath path, Object newValue) {
	    }
	 
	    public void addTreeModelListener(TreeModelListener l) {
	    }
	 
	    public void removeTreeModelListener(TreeModelListener l) {
	    }
	 
	}
	 
	interface I_fileSystem {
	 
	    final public static char DIRECTORY = 'D';
	    final public static char FILE = 'F';
	    final public static char ALL = 'A';
	 
	    public Icon getIcon();
	 
	    public I_fileSystem getChild(char fileType, int index);
	 
	    public int getChildCount(char fileType);
	 
	    public boolean isLeaf(char fileType);
	 
	    public int getIndexOfChild(char fileType, Object child);
	 
	}
	 
	 
	class FolderNode implements I_fileSystem {
	 
	    // private static FolderNode theRoot;
	 
	    private  FileSystemView fsView;
	 
	    private boolean showHiden = true;;
	 
	    private File theFile;
	 
	    private Vector<File> all = new Vector<File>();
	 
	    private Vector<File> folder = new Vector<File>();
	 
	    /**
	     * set that whether apply hiden file.
	     *
	     * @param ifshow
	     */
	    public FolderNode() {
	        fsView = FileSystemView.getFileSystemView();
	        theFile = new File(PC_LOAD_DIR);//fsView.getHomeDirectory();
	        prepareChildren();
	    }
	     
	    public FolderNode(File file) {
	        fsView = FileSystemView.getFileSystemView();
	        theFile = file;
	        prepareChildren();
	    }
	     
	    public void setShowHiden(boolean ifshow) {
	        showHiden = ifshow;
	    }

		public String getHomePath(){
			if(theFile != null){
				return theFile.getPath();
			}
			return null;
		}
	 
	    public Icon getIcon() {
	        return fsView.getSystemIcon(theFile);
	    }
	 
	    public String toString() {
	       // return fsView.
	       return fsView.getSystemDisplayName(theFile);
	    }
	 
	    /**
	     * create a root node. by default, it should be the DeskTop in window file
	     * system.
	     *
	     */
	 
	    private void prepareChildren() {
	 
	      File[] files = fsView.getFiles(theFile, showHiden);
	       for (int i = 0; i < files.length; i++) {
	           all.add(files[i]);
		   String AbsolutePath = files[i].getAbsolutePath();
		   String name = files[i].getName();
			//System.out.println("prepareChildren AbsolutePath:"+AbsolutePath+" name:"+name);	

	           if (files[i].isDirectory()
	                   && !files[i].toString().toLowerCase().endsWith(".lnk")) {
	               folder.add(files[i]);
	           }
	       }
	    }
	 
	    public FolderNode getChild(char fileType, int index) {
	       if (I_fileSystem.DIRECTORY == fileType) {
	           return new FolderNode(folder.get(index));
	       } else if (I_fileSystem.ALL == fileType) {
	           return new FolderNode(all.get(index));
	       } else if (I_fileSystem.FILE == fileType) {
	           return null;
	       } else {
	           return null;
	       }
	    }
	 
	    public int getChildCount(char fileType) {
	       if (I_fileSystem.DIRECTORY == fileType) {
	           return folder.size();
	       } else if (I_fileSystem.ALL == fileType) {
	           return all.size();
	       } else if (I_fileSystem.FILE == fileType) {
	           return -1;
	       } else {
	           return -1;
	       }
	    }
	 
	    public boolean isLeaf(char fileType) {
	       if (I_fileSystem.DIRECTORY == fileType) {
	           return folder.size() == 0;
	       } else if (I_fileSystem.ALL == fileType) {
	           return all.size() == 0;
	       } else if (I_fileSystem.FILE == fileType) {
	           return true;
	       } else {
	           return true;
	       }
	    }
	 
	    public int getIndexOfChild(char fileType, Object child) {
	       if (child instanceof FolderNode) {
	           if (I_fileSystem.DIRECTORY == fileType) {
	               return folder.indexOf(((FolderNode) child).theFile);
	           } else if (I_fileSystem.ALL == fileType) {
	               return all.indexOf(((FolderNode) child).theFile);
	           } else if (I_fileSystem.FILE == fileType) {
	               return -1;
	           } else {
	               return -1;
	           }
	       } else {
	           return -1;
	       }
	    }
	}



	class User {
	    private String name;
	    private String type;
	 
	    public User(String n) {
	        name = n;
	    }
	    public User(String n, String t) {
	        name = n;
		type = t;
	    }
	    public boolean isDirectory(){
		if(type != null && type.equals("d")){
			return true;
		}else{
			return false;
		}
	    }
	    public String toString() {
	        return name;
	    }
	}

	    class AddItem implements ActionListener
	    {
	    	public void actionPerformed(ActionEvent e)
	    	{
	    		DefaultMutableTreeNode newNode = new DefaultMutableTreeNode("\u65b0\u589e\u8282\u70b9");
	    		currTreeNode.add(newNode);
	    		DefaultTreeModel model = (DefaultTreeModel)fileTreeDevice.getModel();
	    		model.nodeStructureChanged(currTreeNode);
	    	}
	    }

		private String getLastName(String fullName, String osStr){
			//String osStr = System.getProperties().getProperty("os.name");	
			if(osStr.equals("Linux")){
				return fullName.substring(fullName.lastIndexOf("/")+1);
			}else{
				return fullName.substring(fullName.lastIndexOf("\\")+1);
			}
		}

	    private void PIfuncHandler(final int function){

		String osStr = System.getProperties().getProperty("os.name");

		TreePath[] treepaths= fileTree.getSelectionPaths();
		String[] srcFileList = null;
		String srcDir = "";
		
		TreePath[] devTreepaths= fileTreeDevice.getSelectionPaths();
		String[] dstFileList = null;
		String dstDir = "";
		
		{
			String homeStr = System.getProperty("user.home");
	  		//System.out.println("actionPerformed plPushBtn homeStr:"+homeStr);

			String homePathStr = null;
			if(plFolderNode != null){
				homePathStr = plFolderNode.getHomePath();
			}
			if(homePathStr == null)
			{
				FileSystemView fsv=FileSystemView.getFileSystemView();
				File file=new File(PC_LOAD_DIR);//fsv.getHomeDirectory();
				homePathStr = file.getPath();
			}		
			//System.out.println("actionPerformed plPushBtn homePathStr:"+homePathStr);

			/*
			FolderNode srcDirObj = null;
			if(treepath != null)
			srcDirObj = (FolderNode)treepath.getLastPathComponent();
			if(srcDirObj != null)
			srcDir = srcDirObj.getHomePath() + "\\";
			//System.out.println("actionPerformed @@@ plPushBtn srcDir:"+srcDir);
			*/	
	/* jdj-tieto-2014-12-3 20:7:25 
			if(treepaths != null){
	  		System.out.println("actionPerformed plPushBtn treepaths:"+treepaths);
		  		System.out.println("actionPerformed plPushBtn treepaths.length:"+treepaths.length);
			}
	 jdj-tieto-2014-12-3 20:7:25 */
			if(treepaths != null && treepaths.length > 0){
				srcFileList = new String[treepaths.length];
				for(int index = 0; index < treepaths.length; index++){
			  		//System.out.println("actionPerformed plPushBtn treepaths["+index+"]:"+treepaths[index]);
					String subNodeName = "";
					FolderNode subNoteObj = null;
					if(treepaths[index] != null)
					subNoteObj = (FolderNode)treepaths[index].getLastPathComponent();
					if(subNoteObj != null)
					subNodeName = subNoteObj.getHomePath();				
					/*
					Object[] obj = treepaths[index].getPath();
					for(int jdj = 0; jdj < obj.length; jdj++){
						if(0 == jdj){
						subNodeName += homeStr + "\\" + obj[jdj] + "\\";
						}else if((obj.length - 1) == jdj){
							subNodeName += obj[jdj];
						}else{
							subNodeName += obj[jdj] + "\\";
						}
					}
					*/
					srcFileList[index] = subNodeName;
				}
			}

			if(devTreepaths != null && devTreepaths.length > 0){

				dstFileList = new String[devTreepaths.length];
				for(int index = 0; index < devTreepaths.length; index++){
			  		//System.out.println("actionPerformed plPushBtn devTreepaths["+index+"]:"+devTreepaths[index]);
					Object[] obj = devTreepaths[index].getPath();
					String subNodeName = "";
					for(int jdj = 0; jdj < obj.length; jdj++){
						if(obj[jdj] != null && obj[jdj].equals(SDCARD_ROOT)){
							subNodeName += obj[jdj];
						}else{
							if((obj.length - 1) == jdj){
								subNodeName += obj[jdj];
							}else{
								subNodeName += obj[jdj] + "/";
							}
						}
					}		
					dstFileList[index] = subNodeName;
			  		//System.out.println("actionPerformed plPushBtn dstFileList["+index+"]:"+dstFileList[index]);
				}
			}
			TreePath treepath = fileTree.getSelectionPath();
			/*
			if(treepath != null){
				Object[] obj = treepath.getPath();
				for(int jdj = 0; jdj < obj.length; jdj++){
					if(jdj == 0){
						srcDir += homeStr + "\\" + obj[jdj] + "\\";
					}else				
					srcDir += obj[jdj] + "\\";
				}	
				//System.out.println("actionPerformed plPushBtn srcDir:"+srcDir);
			}
			*/
			FolderNode srcDirObj = null;
			if(treepath != null)
			srcDirObj = (FolderNode)treepath.getLastPathComponent();
			if(srcDirObj != null){
				if(osStr != null && "Linux".equals(osStr)){
					srcDir = srcDirObj.getHomePath() + "/";
				}else{
					srcDir = srcDirObj.getHomePath() + "\\";
				}
			}
			//System.out.println("actionPerformed @@@ plPushBtn srcDir:"+srcDir);
			
			TreePath devTreepath = fileTreeDevice.getSelectionPath();
			if(devTreepath != null){
				Object[] obj = devTreepath.getPath();
				for(int jdj = 0; jdj < obj.length; jdj++){
					dstDir += obj[jdj] + "/";
				}	
				//System.out.println("actionPerformed plPushBtn dstDir:"+dstDir);
			}

			//if(srcFileList != null && srcFileList.length > 0)
			{
					setADBPath();
					 cmdStringList = "";//*"#!/bin/bash" + */LINE_SEPATATOR;
					//String osStr = System.getProperties().getProperty("os.name");	
			  		//System.out.println("actionPerformed plPushBtn osStr:"+osStr);				
					if(osStr != null && "Linux".equals(osStr)){
						CMD_PATH = CMD_PATH_LINUX;
						LINE_SEPATATOR = "\n";
					}else{
						CMD_PATH = CMD_PATH_WINDOWS;
						LINE_SEPATATOR = "\r\n";
					}
					
					if(function == FUNC_PUSH){
						if(treepaths == null || srcFileList == null || (srcFileList != null && srcFileList.length == 0))
							return;
						for(int index = 0; index < srcFileList.length; index++){				
							//if(osStr != null && "Linux".equals(osStr)){
							//	cmdStringList += ADB_PATH+" push " + srcFileList[index] + " " + dstDir;
							//}else
							//
							{
								cmdStringList += ADB_PATH+" push \"" + srcFileList[index] + "\" \"" + dstDir +"\"";
							}
							if(index != (srcFileList.length - 1))
								cmdStringList += LINE_SEPATATOR;
						}
					}else if(function == FUNC_PULL){
						//System.out.println("actionPerformed FUNC_PULL srcDir:"+srcDir);
						if(srcDir.equals(""))
							return;
						if(devTreepaths == null || dstFileList == null || (dstFileList != null && dstFileList.length == 0))
							return;
						//System.out.println("actionPerformed FUNC_PULL dstFileList.length:"+dstFileList.length);
						for(int index = 0; index < dstFileList.length; index++){		
							//if(osStr != null && "Linux".equals(osStr)){
							//	cmdStringList += ADB_PATH+" pull " + dstFileList[index] + " " + srcDir;
							//}else
							{
								cmdStringList += ADB_PATH+" pull \"" + dstFileList[index] + "\" \"" + srcDir + getLastName(dstFileList[index], "Linux") +"\"";
							}
							if(index != (dstFileList.length - 1))
								cmdStringList += LINE_SEPATATOR;
						}
						//System.out.println("actionPerformed FUNC_PULL cmdStringList:"+cmdStringList);

					}else if(function == FUNC_DELETE){
						if(devTreepaths == null || dstFileList == null || (dstFileList != null && dstFileList.length == 0))
							return;
						//System.out.println("actionPerformed FUNC_DELETE dstFileList.length:"+dstFileList.length);
					
						for(int index = 0; index < dstFileList.length; index++){	
							//if(osStr != null && "Linux".equals(osStr)){
							//	cmdStringList += ADB_PATH+" shell rm -rf " + dstFileList[index];
							//}else
							{
								cmdStringList += ADB_PATH+" shell rm -rf \"" + dstFileList[index] + "\"";
							}
							if(index != (dstFileList.length - 1))
								cmdStringList += LINE_SEPATATOR;
						}

					}
					//System.out.println("PIfuncHandler cmdStringList:"+cmdStringList);
/* irb 2015-3-9 20:58:46 
					boolean writeSuccessfully = false;
 irb 2015-3-9 20:58:46 */
/* irb 2015-3-9 20:9:40 */

/* irb 2015-3-9 21:15:20 
					if(plJDialog == null)
 irb 2015-3-9 21:15:20 */
					{
						plJDialog = new JDialog(this,  "\u63d0\u793a\u6846", true); 
/* irb 2015-3-9 20:47:50 
						plJDialog.setUndecorated(true);
 irb 2015-3-9 20:47:50 */
					       JLabel label = null;
						if(function == FUNC_PUSH || function == FUNC_PULL){
						label = new JLabel("\u8bf7\u7a0d\u4faf\uff0c\u6b63\u5728\u62f7\u8d1d\u6587\u4ef6\u4e2d......");
						}else if(function == FUNC_DELETE){
						label = new JLabel("\u8bf7\u7a0d\u4faf\uff0c\u6b63\u5728\u5220\u9664\u6587\u4ef6\u4e2d......");
						}else{
							return;
						}
					       label.setHorizontalAlignment(JLabel.CENTER); 
 						plJDialog.getContentPane().add(label);
						plJDialog.setResizable(true);
						plJDialog.setSize(390, 100);
						plJDialog.setLocationRelativeTo(this); 				
						plJDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); 
					}
					
				        new Thread()
				        {
				            public void run()
				            {
						  boolean writeSuccessfully = false;
		
							try{
								File file =new File(CMD_PATH);
								if(!file.exists()){
									file.createNewFile();
								}
								
								FileWriter fileWritter = new FileWriter(CMD_PATH);
								BufferedWriter bufferWritter = new BufferedWriter(fileWritter);
								bufferWritter.write(cmdStringList);
								bufferWritter.close();
								//System.out.println("PIfuncHandler write "+CMD_PATH+": successfully");
								writeSuccessfully = true;
							}catch(Exception e){
								//System.out.println("PIfuncHandler write "+CMD_PATH+": failed "+e.toString());
								e.printStackTrace();
								if(plJDialog != null)
						                    		plJDialog.dispose();								
							}		
							if(writeSuccessfully){

								try {
									 String cmdStr = null;
									 String osStr = System.getProperties().getProperty("os.name");
				 					if(osStr != null && "Linux".equals(osStr)){
										 Runtime.getRuntime().exec("chmod 777 "+CMD_PATH);  
										cmdStr = "bash " + CMD_PATH;
				 					}else{
										cmdStr = CMD_PATH;
				 					}

							               Process process = Runtime.getRuntime().exec(cmdStr);  

							               final BufferedReader batchInputStream = new BufferedReader(new InputStreamReader(process.getInputStream()));
							              final  BufferedReader  batchErrorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
							               new Thread(new Runnable() {
							                    String line;
							                    public void run() {
							                       //System.out.println("PIfuncHandler listener batchErrorReader started");

										   String resultStr = "";
							                        try {
							                            while((line=batchErrorReader.readLine()) != null) {
							                               //System.out.println(line);
										          resultStr = resultStr + line + LINE_SEPATATOR;			        
							                           }
											//System.out.println("PIfuncHandler batchErrorReader  resultStr:"+resultStr);

							                        } catch (IOException e) {
							                           e.printStackTrace();  
							                        }

							                    }
							               }).start();								  
							               new Thread(new Runnable() {
							                    String line;
							                    public void run() {
							                       //System.out.println("PIfuncHandler listener batchInputStream started");

										   String resultStr = "";
							                        try {
							                            while((line=batchInputStream.readLine()) != null) {
							                               //System.out.println(line);
										          resultStr = resultStr + line + LINE_SEPATATOR;			        
							                           }
													//System.out.println("PIfuncHandler batchInputStream resultStr:"+resultStr);
											
							                        } catch (IOException e) {
							                           e.printStackTrace();  
							                        }
											//System.out.println("PIfuncHandler batchInputStream function:"+function);
 
											if(function != FUNC_PULL){
												reloadSdcard();
											}

							                    }
							               }).start();

							               int i = process.waitFor();

									if(plJDialog != null)
							                    		plJDialog.dispose();											   
							               //System.out.println("PIfuncHandler i=" + i);
							           } catch (Exception e) {
							               e.printStackTrace();
									if(plJDialog != null)
							                    		plJDialog.dispose();	
							           }						
							}
							
							if(plJDialog != null)
					                    		plJDialog.dispose();
				            }
				        }.start();

					plJDialog.setVisible(true);

					
/* irb 2015-3-9 20:21:20 
					if(plJProgressBar == null){
						plJProgressBar = new JProgressBar(); 
						plJProgressBar.setIndeterminate(true); 
						plJProgressBar.setStringPainted(true); 
						plJProgressBar.setString("Please wait, file Copying......"); 
						add(plJProgressBar);
					}
 irb 2015-3-9 20:21:20 */
/* irb 2015-3-9 20:9:40 */

/* irb 2015-3-9 20:16:34 */
/* irb 2015-3-9 20:53:14 
					plJDialog.dispose();
 irb 2015-3-9 20:53:14 */
/* irb 2015-3-9 20:21:24 
					plJProgressBar.setIndeterminate(false); 
					plJProgressBar.setString("IDLE......"); 
 irb 2015-3-9 20:21:24 */
/* irb 2015-3-9 20:16:34 */

/* irb 2015-3-9 20:54:51 
					try{

						File file =new File(CMD_PATH);
						if(!file.exists()){
							file.createNewFile();
						}
						
						FileWriter fileWritter = new FileWriter(CMD_PATH);
						BufferedWriter bufferWritter = new BufferedWriter(fileWritter);
						bufferWritter.write(cmdStringList);
						bufferWritter.close();
						//System.out.println("PIfuncHandler write "+CMD_PATH+": successfully");
						writeSuccessfully = true;
					}catch(Exception e){
						//System.out.println("PIfuncHandler write "+CMD_PATH+": failed "+e.toString());
						e.printStackTrace();
					}	
 irb 2015-3-9 20:54:51 */

/* irb 2015-3-9 20:54:45 
					if(writeSuccessfully){

						try {
							 String cmdStr = null;
		 					if(osStr != null && "Linux".equals(osStr)){
								 Runtime.getRuntime().exec("chmod 777 "+CMD_PATH);  
								cmdStr = "bash " + CMD_PATH;
		 					}else{
								cmdStr = CMD_PATH;
		 					}

					               Process process = Runtime.getRuntime().exec(cmdStr);  

					               final BufferedReader batchInputStream = new BufferedReader(new InputStreamReader(process.getInputStream()));
					              final  BufferedReader  batchErrorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
					               new Thread(new Runnable() {
					                    String line;
					                    public void run() {
					                       //System.out.println("PIfuncHandler listener batchErrorReader started");

								   String resultStr = "";
					                        try {
					                            while((line=batchErrorReader.readLine()) != null) {
					                               //System.out.println(line);
								          resultStr = resultStr + line + LINE_SEPATATOR;			        
					                           }
									//System.out.println("PIfuncHandler batchErrorReader  resultStr:"+resultStr);

					                        } catch (IOException e) {
					                           e.printStackTrace();  
					                        }

					                    }
					               }).start();								  
					               new Thread(new Runnable() {
					                    String line;
					                    public void run() {
					                       //System.out.println("PIfuncHandler listener batchInputStream started");

								   String resultStr = "";
					                        try {
					                            while((line=batchInputStream.readLine()) != null) {
					                               //System.out.println(line);
								          resultStr = resultStr + line + LINE_SEPATATOR;			        
					                           }
											//System.out.println("PIfuncHandler batchInputStream resultStr:"+resultStr);
									
					                        } catch (IOException e) {
					                           e.printStackTrace();  
					                        }
											//System.out.println("PIfuncHandler batchInputStream function:"+function);
											if(function != FUNC_PULL){
												reloadSdcard();
											}

					                    }
					               }).start();

					               int i = process.waitFor();
					               //System.out.println("PIfuncHandler i=" + i);
					           } catch (Exception e) {
					               e.printStackTrace();
					           }						
					}
 irb 2015-3-9 20:54:45 */
				}
							
		    }
	    }

		private void reloadPC(){

			//plFolderNode=new FolderNode();
			//fileTree.expandPath(new TreePath(plFolderNode));


			plFolderNode=new FolderNode();
			FileSystemModel fs=new FileSystemModel(plFolderNode);
			fileTree = new JTree(fs);

			treeScroll.setViewportView(fileTree);

			
		}

	    private void reloadSdcard(){
		if(fileTreeDeviceTopNode != null){
			fileTreeDeviceTopNode.removeAllChildren();
			
			User rootName = (User)fileTreeDeviceTopNode.getUserObject();
	  		//System.out.println("actionPerformed plDeviceLoad rootName:"+rootName.toString());		
			
			int count = fileTreeDeviceTopNode.getChildCount();
	  		//System.out.println("actionPerformed plDeviceLoad count:"+count);	
			if(count == 0){
				System.out.println("loadSdcard 3 a");
				loadSdcard(SDCARD_ROOT, fileTreeDeviceTopNode);
				System.out.println("loadSdcard 3 b");
			}
		}
	    }

	    private void loadSdcard(String dir, final DefaultMutableTreeNode node){
		setADBPath();	
	try {

	           Process process = Runtime.getRuntime().exec(ADB_PATH+" shell ls -l "+dir);  
	/* jdj-tieto-2014-12-3 21:45:51 
	           final BufferedWriter batchOutputStream = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
	 jdj-tieto-2014-12-3 21:45:51 */
	           final BufferedReader batchInputStream = new BufferedReader(new InputStreamReader(process.getInputStream()));
	          final  BufferedReader  batchErrorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));

	           new Thread(new Runnable() {
	                String line;
	                public void run() {
	                   //System.out.println("loadSdcard listener batchErrorReader started");

			   String resultStr = "";
	                    try {
	                        while((line=batchErrorReader.readLine()) != null) {
	/* jdj-tieto-2014-11-13 19:51:58 
	                           //System.out.println(line);
	 jdj-tieto-2014-11-13 19:51:58 */
			          resultStr = resultStr + line + LINE_SEPATATOR;			        
	                       }
				//System.out.println("loadSdcard batchErrorReader  resultStr:"+resultStr);

	                    } catch (IOException e) {
	                       //e.printStackTrace();  
	                    }

	                }
	           }).start();					

			new Thread(new Runnable() {
				String line;
				public void run() {
					//System.out.println("loadSdcard listener batchInputStream started");
					String fileTypeResultStr = "";
					String[] fileTypeList = null;
					
					String resultStr = "";
					String[] fileList = null;

					int number = 0;
						
					try {
						boolean error = false;
						while((line=batchInputStream.readLine()) != null) {
							
							//System.out.println(line);
							if(line != null){
								if(!line.equals("")){								
									if(line.contains("Not a directory")){
										error = true;
										break;
									}
									
									if(!line.contains("* daemon")){
										//System.out.println(line);
										fileTypeResultStr = fileTypeResultStr + line.substring(0, 1) + "#";
										int item = line.indexOf(":");
										resultStr = resultStr + line.substring(item + 4) + "#";//LINE_SEPATATOR;	
									}

									number++;
								}
							}
						}
						//System.out.println("loadSdcard batchInputStream resultStr:"+resultStr);
						//System.out.println("loadSdcard batchInputStream fileTypeResultStr:"+fileTypeResultStr);
						if(!error){
							if(!resultStr.equals("")){
								fileList = resultStr.split("#");//LINE_SEPATATOR);
							}
							if(!fileTypeResultStr.equals("")){
								fileTypeList = fileTypeResultStr.split("#");//LINE_SEPATATOR);
							}
						}
					} catch (IOException e) {
						//e.printStackTrace();  
					}
					if(fileList != null && fileList.length > 0){
						for(int index = 0; index < fileList.length; index++){
							//System.out.println("loadSdcard batchInputStream fileList["+index+"]:"+fileList[index]);
							//System.out.println("loadSdcard batchInputStream fileTypeList["+index+"]:"+fileTypeList[index]);
							if(fileList[index] != null && !fileList[index].equals("")){
								DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(new User(fileList[index], fileTypeList[index]));
								node.add(newNode);
							}
						}
						DefaultTreeModel model = (DefaultTreeModel)fileTreeDevice.getModel();
						model.nodeStructureChanged(node);
					}
				}
			}).start();			  
	/* jdj-tieto-2014-11-13 19:49:19 
	           new Thread(new Runnable() {
	                final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	                public void run() {
	                   //System.out.println("loadSdcard writer started");
	                    String line;
	                    try {
	                        while ((line =br.readLine()) != null) {
	                           batchOutputStream.write(line + "\r\n");
	                           batchOutputStream.flush();
	                        }
	                    } catch (IOException e) {
	                       //e.printStackTrace();  
	                    }
	                }
	           }).start();
	 jdj-tieto-2014-11-13 19:49:19 */
	           int i = process.waitFor();
	           //System.out.println("loadSdcard i=" + i);
	       } catch (Exception e) {
	           e.printStackTrace();
	       }						

		
			
	/* jdj-tieto-2014-11-13 19:42:36 
		currTreeNode = fileTreeDeviceTopNode;
		DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(new User("\u65b0\u589e\u8282\u70b9"));
		currTreeNode.add(newNode);
		DefaultTreeModel model = (DefaultTreeModel)fileTreeDevice.getModel();
		model.nodeStructureChanged(currTreeNode);
	 jdj-tieto-2014-11-13 19:42:36 */
	    }

	    private void plCMDHandler(String cmdStr){
		try {
			 setADBPath();
			//System.out.println("plCMDHandler cmdStr:"+cmdStr);
			  
		       Process process = Runtime.getRuntime().exec(ADB_PATH + cmdStr);  
	/* jdj-tieto-2014-12-3 21:45:58 
		       final BufferedWriter batchOutputStream = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
	 jdj-tieto-2014-12-3 21:45:58 */
		       final BufferedReader batchInputStream = new BufferedReader(new InputStreamReader(process.getInputStream()));
		      final  BufferedReader  batchErrorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
		       new Thread(new Runnable() {
		            String line;
		            public void run() {
		               //System.out.println("plCMDHandler listener batchErrorReader started");

				   String resultStr = "";
		                try {
		                    while((line=batchErrorReader.readLine()) != null) {
		                       //System.out.println(line);
				          resultStr = resultStr + line + LINE_SEPATATOR;			        
		                   }
					//System.out.println("plCMDHandler batchErrorReader  resultStr:"+resultStr);

		                } catch (IOException e) {
		                   e.printStackTrace();  
		                }

		            }
		       }).start();								  
		       new Thread(new Runnable() {
		            String line;
		            public void run() {
		               //System.out.println("plCMDHandler listener batchInputStream started");

				   String resultStr = "";
		                try {
		                    while((line=batchInputStream.readLine()) != null) {
		                       //System.out.println(line);
				          resultStr = resultStr + line + LINE_SEPATATOR;			        
		                   }
							//System.out.println("plCMDHandler batchInputStream resultStr:"+resultStr);

					reloadSdcard();
					
		                } catch (IOException e) {
		                   e.printStackTrace();  
		                }

		            }
		       }).start();
	/* jdj-tieto-2014-12-3 21:46:4 
		       new Thread(new Runnable() {
		            final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		            public void run() {
		               System.out.println("rcCMDHandler writer started");
		                String line;
		                try {
		                    while ((line =br.readLine()) != null) {
		                       batchOutputStream.write(line + LINE_SEPATATOR);
		                       batchOutputStream.flush();
		                    }
		                } catch (IOException e) {
		                   e.printStackTrace();  
		                }
		            }
		       }).start();
	 jdj-tieto-2014-12-3 21:46:4 */
		       int i = process.waitFor();
		       //System.out.println("plCMDHandler i=" + i);
		   } catch (Exception e) {
		       e.printStackTrace();
		   }	
	    }
		
	    private JPanel createTabContentPushImage(){
			plPanel = new JPanel();
			plPanel.setLayout(null);	   
			
			System.out.println("createTabContentPushImage 1");

			plFolderNode=new FolderNode();
			System.out.println("createTabContentPushImage 1 a");
			FileSystemModel fs=new FileSystemModel(plFolderNode);
//			fs = null;
			System.out.println("createTabContentPushImage 1 b");
			fileTree = new JTree(fs);

			System.out.println("createTabContentPushImage 1 c");

			treeScroll = new JScrollPane();
			System.out.println("createTabContentPushImage 1 d");
			treeScroll.setViewportView(fileTree);
			System.out.println("createTabContentPushImage 1 e");
			plPanel.add(treeScroll);

			System.out.println("createTabContentPushImage 1 f");

			fileTreeDeviceTopNode = new DefaultMutableTreeNode(new User(SDCARD_ROOT));
			/* <-- wangmingdong -11-12-2014 23:35:23 
			top.add(new DefaultMutableTreeNode(new User("\u603b\u7ecf\u7406")));
			top.add(node1);
			top.add(node2);
			--> wangmingdong  */
				
			System.out.println("createTabContentPushImage 2");

			fileTreeDevice = new JTree(fileTreeDeviceTopNode);
			fileTreeDevice.setShowsRootHandles(true);  
			fileTreeDevice.setRootVisible(true); 
			treeScrollDevice = new JScrollPane();
			treeScrollDevice.setViewportView(fileTreeDevice);
			plPanel.add(treeScrollDevice);

			fileTreeDevice.addMouseListener(new MouseAdapter() {
			      public void mouseClicked(MouseEvent e ) {
				//System.out.println("fileTreeDevice mouseClicked e:"+e);   
			        if(SwingUtilities.isRightMouseButton (e) )
			        {
					int selectedCount = fileTreeDevice.getSelectionCount();
					//System.out.println("fileTreeDevice isRightMouseButton selectedCount:"+selectedCount); 
					if(selectedCount == 1){
						int locationRow = fileTreeDevice.getRowForLocation(e.getX(), e.getY());
						//System.out.println("fileTreeDevice isRightMouseButton locationRow:"+locationRow); 
						TreePath selectedTP = fileTreeDevice.getSelectionPath();
						int selectedRow = fileTreeDevice.getRowForPath(selectedTP);
						//System.out.println("fileTreeDevice isRightMouseButton selectedRow:"+selectedRow);     
						if(locationRow == selectedRow){
							//System.out.println("fileTreeDevice isRightMouseButton popup menu"); 
							if(selectedTP != null){
								DefaultMutableTreeNode lastObj = (DefaultMutableTreeNode)(selectedTP.getLastPathComponent());
								//System.out.println("fileTreeDevice isRightMouseButton lastObj:"+lastObj); 
								if(lastObj != null){
									User lastUser = (User)lastObj.getUserObject();
									if(lastUser != null){
										//System.out.println("fileTreeDevice isRightMouseButton lastUser:"+lastUser.toString()); 
										boolean isDir = lastUser.isDirectory();
										//System.out.println("fileTreeDevice isRightMouseButton isDir:"+isDir); 
										plPopupMenu = new JPopupMenu();
										plMenuitemMkdir = new JMenuItem("\u521b\u5efa\u76ee\u5f55");
										plPopupMenu.add(plMenuitemMkdir);
										plMenuitemMkdir.addActionListener(new ActionListener(){
									                @Override
											public void actionPerformed(ActionEvent e){
												String dirName = (String)JOptionPane.showInputDialog(null, "\u8bf7\u8f93\u5165\u76ee\u5f55\u540d\uff1a\n", "\u521b\u5efa\u76ee\u5f55",
													JOptionPane.PLAIN_MESSAGE, null, null, "MSSLcdTest");
												//System.out.println("fileTreeDevice plMenuitemMkdir dirName:"+dirName); 
												if(dirName != null && !dirName.equals("")){
												int selectedCount = fileTreeDevice.getSelectionCount();
												if(selectedCount == 1){
													TreePath selectedTP = fileTreeDevice.getSelectionPath();
													Object[] obj = selectedTP.getPath();
													String subNodeName = "";
													for(int jdj = 0; jdj < obj.length; jdj++){
														if(obj[jdj] != null && obj[jdj].equals(SDCARD_ROOT)){
															subNodeName += obj[jdj];
														}else
														{
															subNodeName += obj[jdj] + "/";
														}
													}		
													//System.out.println("fileTreeDevice plMenuitemMkdir subNodeName:"+subNodeName); 
													plCMDHandler(" shell mkdir \""+subNodeName+dirName+"\"");
												}
												}
											}
										});
										plPopupMenu.show(e.getComponent(), e.getX(), e.getY());
									}
								}
							}
						}
					}
					
			        }
				/*
			          if( jTree.getPathForLocation(e.getX(), e.getY()) != null)
			            jWindow.setVisible(true);
			        */
			      }
			  });
			
		        fileTreeDevice.addTreeExpansionListener(new TreeExpansionListener(){
		            @Override
			    public void treeExpanded(TreeExpansionEvent event){
		                    //System.out.println("treeExpanded");
		            }
		            @Override
			    public void treeCollapsed(TreeExpansionEvent event){
		                    //System.out.println("treeCollapsed");
							
		/* <-- wangmingdong -11-13-2014 0:25:36 
				DefaultMutableTreeNode newNode = new DefaultMutableTreeNode("\u65b0\u589e\u8282\u70b9");
				currTreeNode.add(newNode);
				DefaultTreeModel model = (DefaultTreeModel)fileTreeDevice.getModel();
				model.nodeStructureChanged(currTreeNode);
		--> wangmingdong  */
							
		            }
		        });

			System.out.println("createTabContentPushImage 3");			   
		        fileTreeDevice.addTreeSelectionListener(new TreeSelectionListener() {
		 
		            @Override
		            public void valueChanged(TreeSelectionEvent e) {
		                    //System.out.println("valueChanged");

				currTreeNode = (DefaultMutableTreeNode) fileTreeDevice.getLastSelectedPathComponent();
		 
		                if (currTreeNode == null)
		                    return;
		 
		                Object object = currTreeNode.getUserObject();
		                //if (currTreeNode.isLeaf()) {
		                    User user = (User) object;
		                    //System.out.println("\u4f60\u9009\u62e9\u4e86\uff1a" + user.toString());
		                //}

				  String nodeName = user.toString();
				  if(nodeName != null){
					if(nodeName.equals(SDCARD_ROOT)){
						int count = fileTreeDeviceTopNode.getChildCount();
						//System.out.println("valueChanged SDCARD_ROOT count:"+count);
						if(count == 0){
							System.out.println("loadSdcard 1 a");
							loadSdcard(SDCARD_ROOT, fileTreeDeviceTopNode);
							System.out.println("loadSdcard 1 b");
						}
					}else{
						int count = currTreeNode.getChildCount();
						//System.out.println("valueChanged nodeName:"+nodeName+"  count:"+count);
						String subNodeName = "";
						TreePath selecttionPath = fileTreeDevice.getSelectionPath();
						if(selecttionPath != null){
							Object[] obj = selecttionPath.getPath();
							if(obj != null && obj.length > 0){
								for(int index = 0; index < obj.length; index++){
									//System.out.println("valueChanged obj["+index+"]:"+obj[index]);
									if(obj[index] != null && obj[index].equals(SDCARD_ROOT))
									subNodeName += obj[index];
									else
									subNodeName += obj[index] + "/";
								}
							}
						}
						if(count == 0){
							//System.out.println("valueChanged subNodeName:"+subNodeName);
							System.out.println("loadSdcard 2 a");
							loadSdcard("\""+subNodeName+"\"", currTreeNode);
							System.out.println("loadSdcard 2 b");
						}
					}
				  }
						
		            }
		        });
				

	/* <-- wangmingdong -11-13-2014 0:25:42 */
	/* jdj-tieto-2014-11-13 17:35:17 
		currTreeNode = fileTreeDeviceTopNode;
		DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(new User("\u65b0\u589e\u8282\u70b9"));
		currTreeNode.add(newNode);
		DefaultTreeModel model = (DefaultTreeModel)fileTreeDevice.getModel();
		model.nodeStructureChanged(currTreeNode);
	 jdj-tieto-2014-11-13 17:35:17 */
	/* --> wangmingdong  */

			plLoadBtn = new JButton("\u91cd\u65b0\u52a0\u8f7d");
			plLoadBtn.addActionListener(this);	
			plPanel.add(plLoadBtn);	

			System.out.println("createTabContentPushImage 4");		

			plPushBtn = new JButton("\u63a8\u9001\u5230\u8bbe\u5907");
			plPushBtn.addActionListener(this);	
			plPanel.add(plPushBtn);	

			plDeviceLoad = new JButton("\u91cd\u65b0\u52a0\u8f7d");
			plDeviceLoad.addActionListener(this);	
			plPanel.add(plDeviceLoad);	
			plDevicePull = new JButton("\u53d1\u9001\u5230\u7535\u8111");
			plDevicePull.addActionListener(this);	
			plPanel.add(plDevicePull);	
			plDeviceDel = new JButton("\u5220\u9664");
			plDeviceDel.addActionListener(this);
			System.out.println("createTabContentPushImage 5");		
			plPanel.add(plDeviceDel);		  
			System.out.println("createTabContentPushImage 6");		
				   
			return plPanel;
			
	    }

		
	/* -2014-11-10 15:34:36 */

	    private JPanel rcPanel = null;

	    private JButton rcLTStartBtn = null;
	    private JButton rcLTStopBtn = null;
	    private JTextField rcLTDelayTF = null;
	    private JButton rcLTDelayBtn = null;
	    private JButton rcTouchStartBtn = null;
	    private JButton rcTouchStopBtn = null;

	    private JButton rcVNCInitBtn = null;
	    private JButton rcVNCStartBtn = null;
	    private JButton rcVNCStopBtn = null;	
		
	    private JButton rcKeyPowerBtn = null;
	    private JButton rcKeyVolumeUpBtn = null;
	    private JButton rcKeyVolumeDownBtn = null;
		
	    private JButton rcKeyUpBtn = null;
	    private JButton rcKeyDownBtn = null;
	    private JButton rcKeyLeftBtn = null;
	    private JButton rcKeyRightBtn = null;
	    private JButton rcKeyTabBtn = null;
	    private JButton rcKeyCenterBtn = null;
		
	    private JButton rcKeyMenuBtn = null;
	    private JButton rcKeyHomeBtn = null;
	    private JButton rcKeyBackBtn = null;

	/* jdj-tieto-2014-12-3 17:44:15 
	   class ClearDocument extends Document{
		public void insertString(int offs, String str, AttributeSet a) throws BadLocationException{
			System.out.println("ClearDocument offs:"+offs+" str:"+str);

			super.insertString(offs,str, a);
		}
	   }    
	 jdj-tieto-2014-12-3 17:44:15 */

	    public void layoutRCChilds(int width, int height){
			int padding = 10;
			
			int contentWidth = width - padding * 2;
			int contentHeight = height - padding * 2;

			int childWidth = (contentWidth -padding ) / 2 / 3;
			int childHeight = contentHeight * 1 / 8;
			int offsetX = 0, offsetY = 0;
			int x= 0, y = 0, w = 0, h = 0;

			offsetX = padding;
			offsetY = padding;
			w = childWidth * 3 / 2;
			h = childHeight;
			x = offsetX;
			y = offsetY + childHeight;
			rcLTStartBtn.setBounds(new Rectangle(x, y+5, w - 5, h-5));
			rcLTStopBtn.setBounds(new Rectangle(x + w + 5, y+5, w- 5, h-5));			
			y = offsetY +3*childHeight;
			rcLTDelayTF.setBounds(new Rectangle(x, y+5, w- 5, h-5));
			rcLTDelayBtn.setBounds(new Rectangle(x + w + 5, y+5, w- 5, h- 5));
			y = offsetY + 5*childHeight;
			rcTouchStartBtn.setBounds(new Rectangle(x, y+5, w- 5, h-5));
			rcTouchStopBtn.setBounds(new Rectangle(x + w + 5, y+5, w- 5, h- 5));

			offsetX = 2 * padding + childWidth * 3;
			offsetY = padding;
			w = childWidth * 3 / 2;
			h = childHeight;
			x = offsetX;
			y = offsetY;
			rcVNCInitBtn.setBounds(new Rectangle(x, y + 5, 2 * w, h-5));		
			y = offsetY + childHeight;
			rcVNCStartBtn.setBounds(new Rectangle(x, y + 5, w- 5, h-5));
			rcVNCStopBtn.setBounds(new Rectangle(x + w + 5, y+5, w- 5, h-5));

			w = childWidth;
			y = offsetY + 3*childHeight;
			rcKeyPowerBtn.setBounds(new Rectangle(x, y+ 5, w- 5, h-5));
			rcKeyVolumeUpBtn.setBounds(new Rectangle(x + w + 5, y+ 5, w- 10, h-5));
			rcKeyVolumeDownBtn.setBounds(new Rectangle(x + 2*w + 5, y+ 5, w- 5, h-5));
			
			y = offsetY + 4*childHeight;
			rcKeyUpBtn.setBounds(new Rectangle(x + w+5, y+ 5, w-10, h-5));
			rcKeyLeftBtn.setBounds(new Rectangle(x, y+ 5, w- 5, h-5));
			rcKeyRightBtn.setBounds(new Rectangle(x + 2*w + 5, y+ 5, w- 5, h-5));
			y = offsetY + 5*childHeight;
			rcKeyDownBtn.setBounds(new Rectangle(x + w + 5, y+ 5, w-10, h-5));
			
			y = offsetY + 6*childHeight;
			rcKeyTabBtn.setBounds(new Rectangle(x, y+ 5, w- 5, h-5));
			rcKeyCenterBtn.setBounds(new Rectangle(x + w + 5, y+ 5, w- 10, h-5));
			
			y = offsetY + 7*childHeight;
			rcKeyMenuBtn.setBounds(new Rectangle(x, y+ 5, w- 5, h-5));
			rcKeyHomeBtn.setBounds(new Rectangle(x + w + 5, y+ 5, w- 10, h-5));
			rcKeyBackBtn.setBounds(new Rectangle(x + 2*w+ 5, y+ 5, w- 5, h-5));
			
	    }

	    private void rcCMDHandler(String cmdStr){
		try {
			 setADBPath();
			//System.out.println("rcCMDHandler cmdStr:"+cmdStr);
			  
		       Process process = Runtime.getRuntime().exec(ADB_PATH + cmdStr);  
	/* jdj-tieto-2014-12-3 21:45:58 
		       final BufferedWriter batchOutputStream = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
	 jdj-tieto-2014-12-3 21:45:58 */
		       final BufferedReader batchInputStream = new BufferedReader(new InputStreamReader(process.getInputStream()));
		      final  BufferedReader  batchErrorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
		       new Thread(new Runnable() {
		            String line;
		            public void run() {
		               //System.out.println("rcCMDHandler listener batchErrorReader started");

				   String resultStr = "";
		                try {
		                    while((line=batchErrorReader.readLine()) != null) {
		                       //System.out.println(line);
				          resultStr = resultStr + line + LINE_SEPATATOR;			        
		                   }
					//System.out.println("rcCMDHandler batchErrorReader  resultStr:"+resultStr);

		                } catch (IOException e) {
		                   e.printStackTrace();  
		                }

		            }
		       }).start();								  
		       new Thread(new Runnable() {
		            String line;
		            public void run() {
		               //System.out.println("rcCMDHandler listener batchInputStream started");

				   String resultStr = "";
		                try {
		                    while((line=batchInputStream.readLine()) != null) {
		                       //System.out.println(line);
				          resultStr = resultStr + line + LINE_SEPATATOR;			        
		                   }
							//System.out.println("rcCMDHandler batchInputStream resultStr:"+resultStr);
					
		                } catch (IOException e) {
		                   e.printStackTrace();  
		                }

		            }
		       }).start();
	/* jdj-tieto-2014-12-3 21:46:4 
		       new Thread(new Runnable() {
		            final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		            public void run() {
		               System.out.println("rcCMDHandler writer started");
		                String line;
		                try {
		                    while ((line =br.readLine()) != null) {
		                       batchOutputStream.write(line + LINE_SEPATATOR);
		                       batchOutputStream.flush();
		                    }
		                } catch (IOException e) {
		                   e.printStackTrace();  
		                }
		            }
		       }).start();
	 jdj-tieto-2014-12-3 21:46:4 */
		       int i = process.waitFor();
		       //System.out.println("rcCMDHandler i=" + i);
		   } catch (Exception e) {
		       e.printStackTrace();
		   }	
	    }

	    private void rcCMDHandler2(String cmdStr, final boolean updateDelay){
		try {
			 setADBPath();
			//System.out.println("rcCMDHandler cmdStr:"+cmdStr);
			  
		       Process process = Runtime.getRuntime().exec(ADB_PATH + cmdStr);  
	/* jdj-tieto-2014-12-3 21:46:7 
		       final BufferedWriter batchOutputStream = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
	 jdj-tieto-2014-12-3 21:46:7 */
		       final BufferedReader batchInputStream = new BufferedReader(new InputStreamReader(process.getInputStream()));
		      final  BufferedReader  batchErrorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
		       new Thread(new Runnable() {
		            String line;
		            public void run() {
		               //System.out.println("rcCMDHandler listener batchErrorReader started");

				   String resultStr = "";
		                try {
		                    while((line=batchErrorReader.readLine()) != null) {
		                       //System.out.println(line);
				          resultStr = resultStr + line + LINE_SEPATATOR;			        
		                   }
					//System.out.println("rcCMDHandler batchErrorReader  resultStr:"+resultStr);

		                } catch (IOException e) {
		                   e.printStackTrace();  
		                }

		            }
		       }).start();								  
		       new Thread(new Runnable() {
		            String line;
		            public void run() {
		               //System.out.println("rcCMDHandler listener batchInputStream started");

				   String resultStr = "";
		                try {
		                    while((line=batchInputStream.readLine()) != null) {
		                       //System.out.println(line);
				          resultStr = resultStr + line + LINE_SEPATATOR;			        
		                   }
					//System.out.println("rcCMDHandler batchInputStream resultStr:"+resultStr);
					if(updateDelay){
						if(resultStr != null){
							resultStr = resultStr.replace(LINE_SEPATATOR, "");
							int delayInt = -1;
							try {
								delayInt = Integer.parseInt(resultStr); 
							} catch (Exception ei) {
								delayInt = -1;
							}
							//System.out.println("rcCMDHandler batchInputStream delayInt:"+delayInt);
							if(delayInt != -1){
								rcLTDelayTF.setText(""+delayInt);
							}
						}
					}
					
		                } catch (IOException e) {
		                   e.printStackTrace();  
		                }

		            }
		       }).start();
	/* jdj-tieto-2014-12-3 21:46:12 
		       new Thread(new Runnable() {
		            final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		            public void run() {
		               System.out.println("rcCMDHandler writer started");
		                String line;
		                try {
		                    while ((line =br.readLine()) != null) {
		                       batchOutputStream.write(line + LINE_SEPATATOR);
		                       batchOutputStream.flush();
		                    }
		                } catch (IOException e) {
		                   e.printStackTrace();  
		                }
		            }
		       }).start();
	 jdj-tieto-2014-12-3 21:46:12 */
		       int i = process.waitFor();
		       //System.out.println("rcCMDHandler i=" + i);
		   } catch (Exception e) {
		       e.printStackTrace();
		   }	
	    }

	    public void rcActionHandler(ActionEvent e) {
		if(e != null){		
			if (e.getSource() == rcLTStartBtn) {		
				rcCMDHandler(" shell am broadcast -a \"action.cxb.start\"");
			}else if(e.getSource() == rcLTStopBtn){
				rcCMDHandler(" shell am broadcast -a \"action.cxb.stop\"");
			}else if(e.getSource() == rcLTDelayBtn){
				String delayStr = rcLTDelayTF.getText();
				//System.out.println("rcActionHandler delayStr:"+delayStr);
				int delayInt = -1;
				try {
					delayInt = Integer.parseInt(delayStr); 
				} catch (Exception ei) {
					delayInt = -1;
				}
				if(delayInt >= 500 && delayInt <= 5000){
					rcCMDHandler(" shell am broadcast -a \"action.cxb.delay\" --ei delay "+delayStr);
				}else{
					rcCMDHandler2(" shell getprop persist.sys.mssdelay", true);
				}
			}else if(e.getSource() == rcTouchStartBtn){
				rcCMDHandler(" shell am broadcast -a \"action.rmc.showtouch\" --es status \"start\"");
			}else if(e.getSource() == rcTouchStopBtn){
				rcCMDHandler(" shell am broadcast -a \"action.rmc.showtouch\" --es status \"stop\"");
			}else if(e.getSource() == rcVNCInitBtn){
				rcCMDHandler(" shell am broadcast -a \"action.rmc.init\"");
			}else if(e.getSource() == rcVNCStartBtn){
				rcCMDHandler(" shell am broadcast -a \"action.rmc.start\"");
			}else if(e.getSource() == rcVNCStopBtn){
				rcCMDHandler(" shell am broadcast -a \"action.rmc.stop\"");
			}else if(e.getSource() == rcKeyPowerBtn){
				rcCMDHandler(" shell input keyevent 26");
			}else if(e.getSource() == rcKeyVolumeUpBtn){
				rcCMDHandler(" shell input keyevent 24");
			}else if(e.getSource() == rcKeyVolumeDownBtn){
				rcCMDHandler(" shell input keyevent 25");
			}else if(e.getSource() == rcKeyUpBtn){
				rcCMDHandler(" shell input keyevent 19");
			}else if(e.getSource() == rcKeyDownBtn){
				rcCMDHandler(" shell input keyevent 20");
			}else if(e.getSource() == rcKeyTabBtn){
				rcCMDHandler(" shell input keyevent 61");
			}else if(e.getSource() == rcKeyCenterBtn){
				rcCMDHandler(" shell input keyevent 23");
			}else if(e.getSource() == rcKeyLeftBtn){
				rcCMDHandler(" shell input keyevent 21");
			}else if(e.getSource() == rcKeyRightBtn){
				rcCMDHandler(" shell input keyevent 22");
			}else if(e.getSource() == rcKeyMenuBtn){
				rcCMDHandler(" shell input keyevent 82");
			}else if(e.getSource() == rcKeyHomeBtn){
				rcCMDHandler(" shell input keyevent 3");
			}else if(e.getSource() == rcKeyBackBtn){
				rcCMDHandler(" shell input keyevent 4");
			}
		}
		
	    }
		
	    private JPanel createTabContentRC(){
			rcPanel = new JPanel();
			rcPanel.setLayout(null);	

			rcLTStartBtn = new JButton("\u5c4f\u5e55\u6d4b\u8bd5\u542f\u52a8");
			rcLTStartBtn.addActionListener(this);	
			rcPanel.add(rcLTStartBtn);	
			rcLTStopBtn = new JButton("\u5c4f\u5e55\u6d4b\u8bd5\u505c\u6b62");
			rcLTStopBtn.addActionListener(this);	
			rcPanel.add(rcLTStopBtn);	

			rcLTDelayTF = new HintTextField("\u8f93\u5165\u6570\u5b57\u8303\u56f4\uff1a500~5000");
			rcLTDelayTF.setDocument(new IntegerDocument());
			rcLTDelayTF.setHorizontalAlignment(JTextField.CENTER);
			rcLTDelayTF.setText("xxxx");
			rcPanel.add(rcLTDelayTF);	
			rcLTDelayBtn = new JButton("\u56fe\u7247\u95f4\u9694\u8bbe\u7f6e");
			rcLTDelayBtn.addActionListener(this);	
			rcPanel.add(rcLTDelayBtn);	
			
			rcTouchStartBtn = new JButton("\u89e6\u6478\u663e\u793a");
			rcTouchStartBtn.addActionListener(this);	
			rcPanel.add(rcTouchStartBtn);	
			rcTouchStopBtn = new JButton("\u89e6\u6478\u9690\u85cf");
			rcTouchStopBtn.addActionListener(this);	
			rcPanel.add(rcTouchStopBtn);	

			
			rcVNCInitBtn = new JButton("\u8fdc\u7a0b\u63a7\u5236\u670d\u52a1\u7aef\u521d\u59cb\u5316");
			rcVNCInitBtn.addActionListener(this);	
			rcPanel.add(rcVNCInitBtn);	
			rcVNCStartBtn = new JButton("\u8fdc\u7a0b\u63a7\u5236\u670d\u52a1\u7aef\u542f\u52a8");
			rcVNCStartBtn.addActionListener(this);	
			rcPanel.add(rcVNCStartBtn);	
			rcVNCStopBtn = new JButton("\u8fdc\u7a0b\u63a7\u5236\u670d\u52a1\u7aef\u505c\u6b62");
			rcVNCStopBtn.addActionListener(this);	
			rcPanel.add(rcVNCStopBtn);	
			
			rcKeyPowerBtn = new JButton("Power");
			rcKeyPowerBtn.addActionListener(this);	
			rcPanel.add(rcKeyPowerBtn);	
			rcKeyVolumeUpBtn = new JButton("Volume Up");
			rcKeyVolumeUpBtn.addActionListener(this);	
			rcPanel.add(rcKeyVolumeUpBtn);	
			rcKeyVolumeDownBtn = new JButton("Volume Down");
			rcKeyVolumeDownBtn.addActionListener(this);	
			rcPanel.add(rcKeyVolumeDownBtn);	
			
			rcKeyUpBtn = new JButton("Up");
			rcKeyUpBtn.addActionListener(this);	
			rcPanel.add(rcKeyUpBtn);	
			rcKeyDownBtn = new JButton("Down");
			rcKeyDownBtn.addActionListener(this);	
			rcPanel.add(rcKeyDownBtn);	
			rcKeyLeftBtn = new JButton("Left");
			rcKeyLeftBtn.addActionListener(this);	
			rcPanel.add(rcKeyLeftBtn);	
			rcKeyRightBtn = new JButton("Right");
			rcKeyRightBtn.addActionListener(this);	
			rcPanel.add(rcKeyRightBtn);	
			rcKeyTabBtn = new JButton("Tab");
			rcKeyTabBtn.addActionListener(this);	
			rcPanel.add(rcKeyTabBtn);
			rcKeyCenterBtn = new JButton("Enter");
			rcKeyCenterBtn.addActionListener(this);	
			rcPanel.add(rcKeyCenterBtn);	
			
			rcKeyMenuBtn = new JButton("Menu");
			rcKeyMenuBtn.addActionListener(this);	
			rcPanel.add(rcKeyMenuBtn);	
			rcKeyHomeBtn = new JButton("Home");
			rcKeyHomeBtn.addActionListener(this);	
			rcPanel.add(rcKeyHomeBtn);	
			rcKeyBackBtn = new JButton("Back");
			rcKeyBackBtn.addActionListener(this);	
			rcPanel.add(rcKeyBackBtn);	

			return rcPanel;
	    }

	    public String getLablesString(String key){
		String lablesString = "unknown";
		if(labels != null){
			lablesString = labels.getString(key);
		}
		return lablesString;
	    }

	    public String getValidString(String str){
		if(str != null){
			if(str.length() == 1){
				return "0" + str;
			}
		}
		return str;
	    }

	    public boolean isInteger(String str){
		if(str != null){
			try {
				Integer.parseInt(str); 
			} catch (Exception ei) {
				return false;
			}	
			return true;
		}else{
			return false;
		}
	    }

	    private void switchToRead(){
		pane.setSelectedIndex(TAB_SINGLE_READ);
	    }
		
		
	    private void switchToWrite(){
		pane.setSelectedIndex(TAB_SINGLE_WRITE);
	    }

	    public void actionPerformed(ActionEvent e) {
		if(e != null){
			//System.out.println("actionPerformed e.getActionCommand():"+e.getActionCommand());
			
			if (e.getSource() == swWrite) {		
				//if(mBatch){
					BatchWriteHandlerEn(false, 0);
				//}else{
				//	SingleWriteHandler();
				//}
			}else if(e.getSource() == swRead){
				//if(mBatch){
					BatchReadHandlerEn();
				//}else{		
				//	SingleReadHandler();
				//}
			}
			else if(e.getSource() == swImport){
				ImportHandler(mBatch);
			}else if(e.getSource() == swExport){
				ExportHandler(mBatch);
			}
			else if(e.getSource() == swAddrAdd){
				AddrAddHandler(mBatch, false);
			}else if(e.getSource() == swAddrDel){
				AddrDelHandler(mBatch);
			}		
/* mss-2015-7-2 0:13:50 */
			else if(e.getSource() == swPorchButton){
				swPorchButtonHandler();
			}			
/* mss-2015-7-2 0:13:50 */
	/* <-- wangmingdong -11-11-2014 1:10:21 */
			else if(e.getSource() == plLoadBtn){
				reloadPC();
			}
			else if(e.getSource() == plPushBtn){
					PIfuncHandler(FUNC_PUSH);			
			}
	/* --> wangmingdong  */
			else if(e.getSource() == swLogStartStop){
				if(runningLogExport()){
					stopLogExport();
				}else{
					startLogExport();
				}
			}
			else if(e.getSource() == swLogPathSet){
				saveLogExport();
			}
	/* -2014-11-13 17:36:8 */
			else if(e.getSource() == plDeviceLoad){
				//DefaultMutableTreeNode root = (DefaultMutableTreeNode)fileTreeDevice.getModel().getRoot();
		  		////System.out.println("actionPerformed plDeviceLoad root:"+root);
				reloadSdcard();						
			}
			else if(e.getSource() == plDevicePull){
					PIfuncHandler(FUNC_PULL);
			}
			else if(e.getSource() == plDeviceDel){
					PIfuncHandler(FUNC_DELETE);
			}
	/* -2014-11-13 17:36:8 */
	/* doom 
			else if (e.getSource() == srRead) {		
				SingleReadHandler();
			}else if (e.getSource() == srToWrite) {
				switchToWrite();
			}	
	 doom */
	/* -2014-12-3 11:58:17 */
	 		else{
				rcActionHandler(e);
	 		}
	/* -2014-12-3 11:58:17 */
		}
		
	/* <-- wangmingdong -9-6-2014 11:53:53 
		if (e.getActionCommand().equals("\u8f93\u5165")) {
			
		}else if (e.getActionCommand().equals("\u8f93\u5165")) {

		}
	--> wangmingdong  */
	    }

	/* --> wangmingdong  */
	 
	    public static void main(String[] args) {
	       SwingUtilities.invokeLater(new Runnable() {
	          
	           @Override
	           public void run() {

			Font vFont = new Font("\u5b8b\u4f53", Font.PLAIN, 14);
/* iryun jdj-tieto-2014-12-29 21:11:0 
			Font vFont = new Font("Dialog", Font.PLAIN, 14);
 iryun jdj-tieto-2014-12-29 21:11:0 */
			UIManager.put("ToolTip.font", vFont);
			UIManager.put("Table.font", vFont);
			UIManager.put("TableHeader.font", vFont);
			UIManager.put("TextField.font", vFont);
			UIManager.put("ComboBox.font", vFont);
			UIManager.put("TextField.font", vFont);
			UIManager.put("PasswordField.font", vFont);
			UIManager.put("TextArea.font", vFont);
			UIManager.put("TextPane.font", vFont);
			UIManager.put("EditorPane.font", vFont);
			UIManager.put("FormattedTextField.font", vFont);
			UIManager.put("Button.font", vFont);
			UIManager.put("CheckBox.font", vFont);
			UIManager.put("RadioButton.font", vFont);
			UIManager.put("ToggleButton.font", vFont);
			UIManager.put("ProgressBar.font", vFont);
			UIManager.put("DesktopIcon.font", vFont);
			UIManager.put("TitledBorder.font", vFont);
			UIManager.put("Label.font", vFont);
			UIManager.put("List.font", vFont);
			UIManager.put("TabbedPane.font", vFont);
			UIManager.put("MenuBar.font", vFont);
			UIManager.put("Menu.font", vFont);
			UIManager.put("MenuItem.font", vFont);
			UIManager.put("PopupMenu.font", vFont);
			UIManager.put("CheckBoxMenuItem.font", vFont);
			UIManager.put("RadioButtonMenuItem.font", vFont);
			UIManager.put("Spinner.font", vFont);
			UIManager.put("Tree.font", vFont);
			UIManager.put("ToolBar.font", vFont);
			UIManager.put("OptionPane.messageFont", vFont);
			UIManager.put("OptionPane.buttonFont", vFont);
			   
	              new Main("DEBUG ONLINE").runTest();
	           }
	       });
	    }
	 
	 
	}
 
 class IntegerDocument extends PlainDocument {

  public void insertString(int offs, String str, AttributeSet a)
    throws BadLocationException {

   if (str == null) {
    return;
   }

   try {
	    Integer.parseInt(str); 
   } catch (Exception ep) {
   		Toolkit.getDefaultToolkit().beep();
/* <-- wangmingdong -9-6-2014 13:17:57 
	    JOptionPane.showMessageDialog(Main.this,
	      "\u8bf7\u8f93\u5165\u6570\u5b57", null, JOptionPane.ERROR_MESSAGE);
--> wangmingdong  */
	    return;
   }
	   super.insertString(offs, str, a);
  }
 }

      
